JUnit4Printtokens2 白盒测试方法
JUnit4Printtokens2 白盒测试方法
本文提供 JUnit4Printtokens2 代码的白盒测试方法,涵盖了 open_character_stream、get_char、unget_char、open_token_stream、is_token_end、token_type、print_token、is_comment、is_keyword、is_char_constant、is_num_constant、is_str_constant 等方法的测试用例。
1. open_character_stream_whitebox_test()
输入:
fname = null
预期输出:
br不为 null
输入:
fname = 'test.txt'(存在的文件)
预期输出:
br不为 null
输入:
fname = 'nonexistent.txt'(不存在的文件)
预期输出:
- 'The file nonexistent.txt doesn't exists' 打印到控制台
br为 null
2. get_char_whitebox_test()
输入:
br = new BufferedReader(new StringReader('abc'))
预期输出:
- 第一次调用
get_char()返回 'a' - 第二次调用
get_char()返回 'b' - 第三次调用
get_char()返回 'c'
3. unget_char_whitebox_test()
输入:
ch = 'a'br = new BufferedReader(new StringReader('abc'))
预期输出:
- 第一次调用
unget_char(ch, br)不会改变流中的当前位置 - 第二次调用
get_char()返回 'a'
4. open_token_stream_whitebox_test()
输入:
fname = null
预期输出:
br不为 null
输入:
fname = 'test.txt'(存在的文件)
预期输出:
br不为 null
输入:
fname = 'nonexistent.txt'(不存在的文件)
预期输出:
- 'The file nonexistent.txt doesn't exists' 打印到控制台
br为 null
5. is_token_end_whitebox_test()
输入:
str_com_id = 0res = 32
预期输出:
is_token_end返回 true
输入:
str_com_id = 1res = 10
预期输出:
is_token_end返回 true
输入:
str_com_id = 2res = 9
预期输出:
is_token_end返回 true
输入:
str_com_id = 0res = 59
预期输出:
is_token_end返回 true
输入:
str_com_id = 0res = 97
预期输出:
is_token_end返回 false
6. token_type_whitebox_test()
输入:
tok = 'and'
预期输出:
token_type返回 1
输入:
tok = '+'
预期输出:
token_type返回 2
输入:
tok = 'abc'
预期输出:
token_type返回 3
输入:
tok = '123'
预期输出:
token_type返回 41
输入:
tok = '#a'
预期输出:
token_type返回 43
输入:
tok = ''abc''
预期输出:
token_type返回 42
输入:
tok = ';abc'
预期输出:
token_type返回 5
输入:
tok = 'abc123'
预期输出:
token_type返回 3
输入:
tok = 'abc+'
预期输出:
token_type返回 0
7. print_token_whitebox_test()
输入:
tok = 'and'
预期输出:
- 'keyword,'and'.\n' 打印到控制台
输入:
tok = '+'
预期输出:
- 'spec_symbol,+ ' 打印到控制台
输入:
tok = 'abc'
预期输出:
- 'identifier,abc.\n' 打印到控制台
输入:
tok = '123'
预期输出:
- 'numeric,123.\n' 打印到控制台
输入:
tok = '#a'
预期输出:
- 'character,a.\n' 打印到控制台
输入:
tok = ''abc''
预期输出:
- 'string,'abc'.\n' 打印到控制台
输入:
tok = ';abc'
预期输出:
- 'comment,;abc.\n' 打印到控制台
输入:
tok = 'abc+'
预期输出:
- 'error,'abc+'.\n' 打印到控制台
8. is_comment_whitebox_test()
输入:
ident = ';abc'
预期输出:
is_comment返回 true
输入:
ident = 'abc'
预期输出:
is_comment返回 false
9. is_keyword_whitebox_test()
输入:
str = 'and'
预期输出:
is_keyword返回 true
输入:
str = 'not'
预期输出:
is_keyword返回 false
10. is_char_constant_whitebox_test()
输入:
str = '#a'
预期输出:
is_char_constant返回 true
输入:
str = '#123'
预期输出:
is_char_constant返回 false
11. is_num_constant_whitebox_test()
输入:
str = '123'
预期输出:
is_num_constant返回 true
输入:
str = 'abc'
预期输出:
is_num_constant返回 false
12. is_str_constant_whitebox_test()
输入:
str = ''abc''
预期输出:
is_str_constant返回 true
输入:
str = 'abc'
预期输出:
is_str_constant返回 false
13. is_identifier_whitebox_test()
输入:
str = 'abc'
预期输出:
is_identifier返回 true
输入:
str = '123'
预期输出:
is_identifier返回 false
输入:
str = 'abc123'
预期输出:
is_identifier返回 true
输入:
str = '123abc'
预期输出:
is_identifier返回 false
14. is_spec_symbol_whitebox_test()
输入:
c = '('
预期输出:
is_spec_symbol返回 true
输入:
c = ')'
预期输出:
is_spec_symbol返回 true
输入:
c = '['
预期输出:
is_spec_symbol返回 true
输入:
c = ']'
预期输出:
is_spec_symbol返回 true
输入:
c = '/'
预期输出:
is_spec_symbol返回 true
输入:
c = ''`
预期输出:
is_spec_symbol返回 true
输入:
c = ','
预期输出:
is_spec_symbol返回 true
输入:
c = 'a'
预期输出:
is_spec_symbol返回 false
原文地址: https://www.cveoy.top/t/topic/jKIm 著作权归作者所有。请勿转载和采集!