[GRASS-SVN] r58814 - grass/trunk/raster/r.category

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 30 14:26:44 PST 2014


Author: wenzeslaus
Date: 2014-01-30 14:26:43 -0800 (Thu, 30 Jan 2014)
New Revision: 58814

Modified:
   grass/trunk/raster/r.category/test_rcategory_doctest.txt
Log:
r.category: improved test with input separators, multiple word labels, extreme cases and non-random data

Modified: grass/trunk/raster/r.category/test_rcategory_doctest.txt
===================================================================
--- grass/trunk/raster/r.category/test_rcategory_doctest.txt	2014-01-30 21:38:27 UTC (rev 58813)
+++ grass/trunk/raster/r.category/test_rcategory_doctest.txt	2014-01-30 22:26:43 UTC (rev 58814)
@@ -8,27 +8,27 @@
 Data preparation
 ================
 
->>> run_command('r.mapcalc', expression='test = rand(1 , 3)')
+>>> run_command('r.mapcalc', expression='test = if(col() < 3, col(), 2)')
 0
->>> print(read_command('r.info', map='test',flags='r'))
+>>> print(read_command('r.info', map='test', flags='r'))
 min=1
 max=2
 <BLANKLINE>
->>> run_command('r.mapcalc', expression='test_14 = rand(1 , 5)')
+>>> run_command('r.mapcalc', expression='test_14 = if(col() < 5, col(), 4)')
 0
->>> print(read_command('r.info', map='test_14',flags='r'))
+>>> print(read_command('r.info', map='test_14', flags='r'))
 min=1
 max=4
 <BLANKLINE>
->>> run_command('r.mapcalc', expression='test_d = double(rand(0 , 10))/2')
+>>> run_command('r.mapcalc', expression='test_d = if(col() < 5, col() / 2., 4.5)')
 0
->>> print(read_command('r.info', map='test_d',flags='r'))
-min=0
+>>> print(read_command('r.info', map='test_d', flags='r'))
+min=0.5
 max=4.5
 <BLANKLINE>
 
 
-Basic tnput and output
+Basic input and output
 ======================
 
 >>> write_command('r.category', map='test', rules='-', separator=':', stdin="""
@@ -125,6 +125,105 @@
 <BLANKLINE>
 
 
+Separators in input
+===================
+
+>>> write_command('r.category', map='test', separator='comma', rules='-', stdin="""
+... 1,treesA
+... 2,waterA
+... """)
+0
+>>> print(read_command('r.category', map='test', separator='space'))
+1 treesA
+2 waterA
+<BLANKLINE>
+
+>>> write_command('r.category', map='test', separator=',', rules='-', stdin="""
+... 1,treesB
+... 2,waterB
+... """)
+0
+>>> print(read_command('r.category', map='test', separator='space'))
+1 treesB
+2 waterB
+<BLANKLINE>
+
+>>> write_command('r.category', map='test', separator='|', rules='-', stdin="""
+... 1|treesC
+... 2|waterC
+... """)
+0
+>>> print(read_command('r.category', map='test', separator=' '))
+1 treesC
+2 waterC
+<BLANKLINE>
+
+Multi words input
+=================
+
+>>> write_command('r.category', map='test', separator='|', rules='-', stdin="""
+... 1|small trees
+... 2|deep water
+... """)
+0
+>>> print(read_command('r.category', map='test', separator=' '))
+1 small trees
+2 deep water
+<BLANKLINE>
+
+>>> write_command('r.category', map='test', separator='tab', rules='-', stdin="""
+... 1\tvery small trees
+... 2\tvery deep water
+... """)
+0
+>>> print(read_command('r.category', map='test', separator=':'))
+1:very small trees
+2:very deep water
+<BLANKLINE>
+
+
+Extreme and incorrect inputs
+============================
+
+Some of these commands should not work and return 1.
+
+>>> write_command('r.category', map='test', separator='comma', rules='-', stdin="""
+... 1,trees, very green
+... 2,water, very deep
+... """)
+1
+
+>>> write_command('r.category', map='test', separator='|', rules='-', stdin="""
+... 1|trees, very green
+... 2|water, very deep
+... """)
+0
+>>> print(read_command('r.category', map='test', separator='space'))
+1 trees, very green
+2 water, very deep
+<BLANKLINE>
+
+>>> write_command('r.category', map='test', separator='tab', rules='-', stdin="""
+... 1\tvery green trees
+... 2\tvery deep\t water
+... """)
+1
+>>> print(read_command('r.category', map='test', separator='space'))
+1 trees, very green
+2 water, very deep
+<BLANKLINE>
+
+>>> write_command('r.category', map='test', separator=' ', rules='-', stdin="""
+... 1 very green
+... 2 very deep
+... """)
+1
+>>> print(read_command('r.category', map='test', separator='space'))
+1 trees, very green
+2 water, very deep
+<BLANKLINE>
+
+
 Clean the results
 =================
 



More information about the grass-commit mailing list