JUnit4Printtokens2 白盒测试方法

本文提供 JUnit4Printtokens2 代码的白盒测试方法,涵盖了 open_character_streamget_charunget_charopen_token_streamis_token_endtoken_typeprint_tokenis_commentis_keywordis_char_constantis_num_constantis_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 = 0
  • res = 32

预期输出:

  • is_token_end 返回 true

输入:

  • str_com_id = 1
  • res = 10

预期输出:

  • is_token_end 返回 true

输入:

  • str_com_id = 2
  • res = 9

预期输出:

  • is_token_end 返回 true

输入:

  • str_com_id = 0
  • res = 59

预期输出:

  • is_token_end 返回 true

输入:

  • str_com_id = 0
  • res = 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
JUnit4Printtokens2 白盒测试方法

原文地址: https://www.cveoy.top/t/topic/jKIm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录