charmap.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 

class TEST_CHAR_MAP

class TEST_CHAR_MAP is -- This is a test program to test the cultural char mapping class. -- Note that it is not portable for simplicity in building a local library. -- Version 1.0 Oct 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 13 Oct 97 kh Original include TEST ; const File_Name : STR := "map-test" ; main is class_name("CHAR_MAP") ; lib : LIBCHARS := LIBCHARS::default ; chmap : CHAR_MAP := CHAR_MAP::create ; test("create",~void(chmap),true.str) ; if void(chmap) then finish ; return end ; -- a simple case maplet creation FAILURE test if needed -- maplet : CASE_MAPLET := CASE_MAPLET::create( -- CHAR_CODE::create(16,LIBCHARS::default),-32,32) ; -- can now build a map for testing! test("valid element [0,32,12] insert", chmap.insert(CASE_MAPLET::create(CHAR_CODE::create( 0,LIBCHARS::default),32.int,12)).str,true.str) ; test("invalid element [16,-16,8] insert", chmap.insert(CASE_MAPLET::create(CHAR_CODE::create( 16,LIBCHARS::default),(-16).int,8)).str,false.str) ; test("valid element [100,-56,32] insert", chmap.insert(CASE_MAPLET::create(CHAR_CODE::create( 100,LIBCHARS::default),(-56).int,32)).str,true.str) ; test("limit element [224,-32,32] insert", chmap.insert(CASE_MAPLET::create(CHAR_CODE::create( 224,LIBCHARS::default),(-32).int,32)).str,true.str) ; -- now write to a file (which can be separately inspected for -- correctness!!). fyle : BIN_FILE := BIN_FILE::open_for_write(File_Name) ; if void(fyle) then fyle := BIN_FILE::create_for_write(File_Name) ; if void(fyle) then raise File_Name end end ; chmap.write(fyle) ; fyle.flush ; fyle.close ; -- now read the file to a second map and test both!! fyle := BIN_FILE::open_for_read(File_Name) ; test("read " + File_Name,(~void(fyle)).str,true.str) ; if void(fyle) then -- Oh! Dear! finish ; return end ; cursor : BIN_CURSOR := fyle.buffer.binstr.cursor ; fyle.close ; -- finished with the file now! filemap : CHAR_MAP := CHAR_MAP::build(cursor) ; test("build map",(~void(filemap)).str,true.str) ; if void(filemap) then finish ; return end ; -- Now the to-range tests! The tests are restricted to codes in -- the first octet to permit portability and valid testing! ch_code : CHAR_CODE := CHAR_CODE::create(0,lib) ; test("to_range(0) value",chmap.to_range(ch_code).card.str,32.str) ; test("to_range(0) equality",chmap.to_range(ch_code).str, filemap.to_range(ch_code).str) ; ch_code := CHAR_CODE::create(11,lib) ; test("to_range(11) value",chmap.to_range(ch_code).card.str,43.str) ; test("to_range(11) equality",chmap.to_range(ch_code).str, filemap.to_range(ch_code).str) ; ch_code := CHAR_CODE::create(12,lib) ; test("to_range(12) value",chmap.to_range(ch_code).card.str,12.str) ; test("to_range(12) equality",chmap.to_range(ch_code).str, filemap.to_range(ch_code).str) ; ch_code := CHAR_CODE::create(16,lib) ; test("not in range(16)",chmap.to_range(ch_code).card.str,16.str) ; test("not in range(16) equality",chmap.to_range(ch_code).str, filemap.to_range(ch_code).str) ; ch_code := CHAR_CODE::create(100,lib) ; test("to_range(100) value",chmap.to_range(ch_code).card.str,44.str) ; test("to_range(100) equality",chmap.to_range(ch_code).str, filemap.to_range(ch_code).str) ; ch_code := CHAR_CODE::create(224,lib) ; test("to_range(224) value",chmap.to_range(ch_code).card.str,192.str) ; test("to_range(224) equality",chmap.to_range(ch_code).str, filemap.to_range(ch_code).str) ; -- now the to-domain tests! The results will to some extent -- be dependent on the local culture, which is why certain tests -- include a void check! ch_code := CHAR_CODE::create(32,lib) ; test("to_domain(32) value",chmap.to_domain(ch_code).card.str,0.str) ; test("to_domain(32) equality",chmap.to_domain(ch_code).str, filemap.to_domain(ch_code).str) ; ch_code := CHAR_CODE::create(43,lib) ; test("to_domain(43) value",chmap.to_domain(ch_code).card.str,11.str) ; test("to_domain(43) equality",chmap.to_domain(ch_code).str, filemap.to_domain(ch_code).str) ; ch_code := CHAR_CODE::create(44,lib) ; test("to_domain(44) value",chmap.to_domain(ch_code).card.str,100.str) ; test("to_domain(44) equality",chmap.to_domain(ch_code).str, filemap.to_domain(ch_code).str) ; ch_code := CHAR_CODE::create(223,lib) ; test("to_domain(255) value",chmap.to_domain(ch_code).card.str,255.str) ; test("to_domain(255) equality",chmap.to_domain(ch_code).str, filemap.to_domain(ch_code).str) ; ch_code := CHAR_CODE::create(224,lib) ; test("to_domain(224) value",chmap.to_domain(ch_code).card.str,224.str) ; test("to_domain(224) equality",chmap.to_domain(ch_code).str, filemap.to_domain(ch_code).str) ; -- finally discard the test file! cwd : DIRECTORY := DIRECTORY::current ; cwd.delete(File_Name) ; finish end ; end ; -- TEST_CHAR_MAP