下图中的主要问题是,当添加“check Result end”语句时,它会自动失败并在调试器中显示“CHECK_VIOLATION”错误。
此外,HASH_TABLE 不会存储给它的所有项目,但我通过切换 HASH_TABLE[G, INTEGER] 而不是使用当前的 HASH_TABLE[INTEGER, G] 解决了这个问题
我的主要问题是为什么它总是抛出 Check_violation 并在看到“检查结果结束”语句时失败?也许 HAS[...] 功能不好?
目前,任何带有“检查结果结束”的测试用例功能都会使其为假并抛出 CHECK_VILOATION
代码:
class
MY_BAG[G -> {HASHABLE, COMPARABLE}]
inherit
ADT_BAG[G]
create
make_empty, make_from_tupled_array
convert
make_from_tupled_array ({ARRAY [TUPLE [G, INTEGER]]})
feature{NONE} -- creation
make_empty
do
create table.make(1)
end
make_from_tupled_array (a_array: ARRAY [TUPLE [x: G; y: INTEGER]])
require else
non_empty: a_array.count >= 0
nonnegative: is_nonnegative(a_array)
do
create table.make(a_array.count)
across a_array as a
loop
table.force (a.item.y, a.item.x)
end
end
feature -- attributes
table: HASH_TABLE[INTEGER, G]
counter: INTEGER
测试代码:
t6: BOOLEAN
local
bag: MY_BAG [STRING]
do
comment ("t6:repeated elements in contruction")
bag := <<["foo",4], ["bar",3], ["foo",2], ["bar",0]>> -- test passes
Result := bag ["foo"] = 5 -- test passes
check Result end -- test fails (really weird but as soon as check statement comes it fails)
Result := bag ["bar"] = 3
check Result end
Result := bag ["baz"] = 0
end