Skip to content

Instantly share code, notes, and snippets.

@marpo60
Last active November 11, 2022 19:03
Show Gist options
  • Save marpo60/a21308584ee977c607360042e2aeaaf2 to your computer and use it in GitHub Desktop.
Save marpo60/a21308584ee977c607360042e2aeaaf2 to your computer and use it in GitHub Desktop.
ElixirConf2022

Mastermind

Mix.install([
  {:stream_data, "~> 0.5"},
  {:kino, "~> 0.7.0"}
])

Section

# Structure
# [1,2,3,4]
defmodule Mastermind do
end
ExUnit.start(autorun: false)

defmodule Test do
  use ExUnit.Case, async: true

  use ExUnitProperties

  test "Red Score" do
    assert Mastermind.red_count([1, 2, 3, 4], [1, 2, 3, 4]) == 4
    assert Mastermind.red_count([9, 9, 3, 4], [1, 2, 3, 4]) == 2
    assert Mastermind.red_count([0, 0, 0, 0], [1, 2, 3, 4]) == 0
  end
  
    test "Miss Score" do
    assert Mastermind.miss_count([4,1,2,3], [1, 2, 3, 4]) == 0
    assert Mastermind.miss_count([0,0,0,0], [1, 2, 3, 4]) == 4
    assert Mastermind.miss_count([1,2,3,9], [1, 2, 3, 4]) == 1
  end

  test "White Score" do
    assert Mastermind.white_count([4,1,2,3], [1, 2, 3, 4]) == 4
    assert Mastermind.white_count([1,2,4,3], [1, 2, 3, 4]) == 2
    assert Mastermind.white_count([1,2,2,2], [2, 1, 1, 1]) == 2
    assert Mastermind.white_count([0,0,0,0], [1, 2, 3, 4]) == 0
  end
end

ExUnit.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment