Hi I am trying to learn quickcheck (quviq) in erlang and I have come across an exercise where I have to test a simulated cache with symbolic calls. However I encounter problems because I get an
31> eqc:quickcheck(test_cache:prop_cache()).
Failed! Reason:
{'EXIT',{{badfun,{call,test_cache,mkt,[set,{0,10}]}},
[{test_cache,'-prop_cache/0-fun-0-',1,
[{file,"test_cache.erl"},{line,79}]}]}}
After 1 tests.
{c,0,10,{call,test_cache,mkt,[set,{0,10}]}}
Shrinking ..(2 times)
Reason:
{'EXIT',{{badfun,{call,test_cache,mkt,[set,{0,2}]}},
[{test_cache,'-prop_cache/0-fun-0-',1,
[{file,"test_cache.erl"},{line,79}]},
{eqc_lazy_lists,lazy_safe_map,2,
[{file,"../src/eqc_lazy_lists.erl"},{line,38}]}]}}
{a,0,2,{call,test_cache,mkt,[set,{0,2}]}}
false
error when trying to call a function that is called symbolically and saved/stored in a variable such that it might be called with different pattern matches as seen in the response to anonymous function and pattern matching .
Edited:
In the below code I get the error when calling the TT1 variable in the prop_cache()
with TT1(new)
for instance. Which normally would return the {changed_value, Value, Cost}
but doesn't do so (with or without the eval(...)
):
mkt(set, {Value, Cost}) ->
Val = fun(new) -> {changed_value, Value, Cost};
({exst, _Value}) -> {changed_value, Value, Cost}
end,
io:format("mkt Gets here ~p~n", [Val]),
Val.
sym_mkt(Opr, Args) -> {call, ?MODULE, mkt, [Opr, Args]}.
term_transf(KeyGen) ->
oneof(
[ ?LET({K, V, C}, {KeyGen, int(), cost()},
return ({K, V, C, sym_mkt(set,{V,C})}))
]).
prop_cache()->
?FORALL({K1, V1, C1, TT1},
term_transf(key()),
begin
%% arbitrary high capacity to ensure cache can hold all items
{ok, F} = cache:new(999999),
equals({changed_value, V1,C1}, eval(TT1(new)))
end
).
For reference (although not important to solving my issue): new(C)
returns {ok, Pid}
with capacity C. Furthermore it is placed in a module called cache
and creates the simulated cache.
1条答案
按热度按时间erhoui1w1#
这个错误告诉你,你正在尝试调用一个错误的函数
{call,test_cache,mkt,[set,{0,10}]}
,它实际上不是一个函数。当你试图在调用eval/1
之前调用TT1(new)
时会发生这种情况。首先执行eval(TT1)
,然后将参数new
应用于返回的函数来解决这个问题。