Skip to content

Instantly share code, notes, and snippets.

@adolfont
Last active February 1, 2024 20:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adolfont/45cd57d2e9ef020ed164419f970235ad to your computer and use it in GitHub Desktop.
Save adolfont/45cd57d2e9ef020ed164419f970235ad to your computer and use it in GitHub Desktop.
Calculator with TDD

Calculator with TDD

Livebook Button

Run in Livebook

Code

defmodule Calculator do
  def add(a, b) do
    a + b
  end

  def multiply(a, b) do
    a * b
  end
end

Tests

ExUnit.start(auto_run: false)

defmodule CalculatorTest do
  use ExUnit.Case, async: false

  describe "Testing the addition function" do
    test "2 plus 3 is 5" do
      assert Calculator.add(2, 3) == 5
    end

    test "2 plus 2 is 4" do
      assert Calculator.add(2, 2) == 4
    end
  end

  describe "Testing the multiplication function" do
    test "2 times 3 is 6" do
      assert Calculator.multiply(2, 3) == 6
    end

    test "2 times 20 is 40" do
      assert Calculator.multiply(2, 20) == 40
    end
  end
end

ExUnit.run()
@adolfont
Copy link
Author

@adolfont
Copy link
Author

@adolfont
Copy link
Author

adolfont commented Apr 27, 2022

@adolfont
Copy link
Author

@adolfont
Copy link
Author

@adolfont
Copy link
Author

adolfont commented Apr 27, 2022

<iframe width="560" height="315" src="https://www.youtube.com/embed/HzNdVlIpFgI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

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