【发布时间】:2017-05-10 00:04:11
【问题描述】:
最近写了一个如下函数:
@doc """
Creates a new deck, shuffles its cards and retrieves a hand of
cards from it.
The `hand_size` argument indicates the size of the hand.
## Examples
iex> {hand, _deck_remainder} = Cards.create_hand 2
iex> hand
["Ace of Clubs", "Four of Hearts"]
"""
def create_hand(hand_size) do
create_deck
|> shuffle
|> deal(hand_size)
end
需要考虑的要点:
-
create_deck/0返回一个字符串列表,如["Two of Clubs", "Four of Hearts"] -
shuffle/1获取字符串列表并使用Enum.shuffle/1将它们打乱 -
deal/2返回一个像{["Ace of Spades"], ["Five of Clubs"]}这样的元组
然后我运行mix test任务,出现如下错误:
看起来 mix test 正在考虑将 @doc 注释中的示例作为单元测试。
由于shuffle/1 随机排列列表中的字符串,示例(作为单元测试)崩溃。
我想从mix test 中排除这些示例...这样做是个好主意吗?如果是这样,我该如何排除它们?
【问题讨论】:
-
请参阅hexdocs.pm/ex_unit/ExUnit.DocTest.html,您需要为您的模块禁用
doctest。将来,请以文本而不是图像的形式包含错误。 -
感谢@sobolevn 提供的信息和建议
标签: elixir elixir-mix