我编写的函数的doctest失败。我收到的错误消息说generate_operands/0
是未定义的。我的意图是在文档测试中使用generate_operands/6
的默认参数-这可能吗?建议执行我想要的操作,还是故意犯错误?
函数如下:
@doc """
Generate the operands for arithmetic practice problems.
## Examples
iex> operands = generate_operands()
iex> length(operands)
10
iex> hd(operands) |> length()
5
"""
@spec generate_operands(
integer,
integer,
boolean,
integer,
boolean,
SimplePRNG.t()
) :: [
[integer()],
...
]
def generate_operands(
num_probs \\ 10,
num_ops \\ 5,
equal_num \\ false,
max_power \\ 5,
equal_mag \\ false,
prng \\ SimplePRNGImpl
)
def generate_operands(num_probs, num_ops, equal_num, max_power, equal_mag, prng) do
IO.puts("generate_operands()")
end
错误消息是:
== Compilation error in file test/arithmetic_practice_test.exs ==
** (CompileError) (for doctest at) lib/arithmetic_practice.ex:25: undefined function generate_operands/0
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir) lib/code.ex:767: Code.require_file/2
(elixir) lib/kernel/parallel_compiler.ex:209: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
答案 0 :(得分:2)
您需要将带有ModuleName的完整路径用于generate_operands。 检查下面的代码。
@doc """
Generate the operands for arithmetic practice problems.
## Examples
iex> operands = MyModule.InnerModule.generate_operands()
iex> length(operands)
10
iex> hd(operands) |> length()
5
"""