我正在为 Erlang 代码编写 EUnit 测试。
我有一个源模块:
-module(prob_list).
-export([intersection/2,union/2]).
probability([], _Item) -> false;
probability([{First,Probability}|Rest], Item) ->
if
First == Item -> Probability;
true -> probability(Rest, Item)
end.
...
...
...
和一个单元测试模块:
-module(prob_list_tests).
-include_lib("eunit/include/eunit.hrl").
-define(TEST_LIST,[{3,0.2},{4,0.6},{5,1.0},{6,0.5}]).
-define(TEST_LIST1,[{2,0.9},{3,0.6},{6,0.1},{8,0.5}]).
-define(TEST_UNO_LIST,[{2,0.5}]).
probability_test() -> ?assertNot(prob_list:probability([],3)),
?assertEqual(0.5,prob_list:probability(?TEST_UNO_LIST,2)),
?assertNot(prob_list:probability(?TEST_UNO_LIST,3)),
?assertEqual(0.2,prob_list:probability(?TEST_LIST,3)),
?assertEqual(1.0,prob_list:probability(?TEST_LIST,5)),
?assertNot(prob_list:probability(?TEST_LIST,7)).
...
...
...
当我运行 eunit:test(prob_list,[verbose])
它说:
prob_list_tests: probability_test...*failed*
::undef
probability/2
但是当我在我的模块中导出时prob_list
,一切都很好。
有什么方法可以测试私有函数吗?