1
exercism fetch ruby pythagorean-triplet

pythagorean_triplet_test.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'minitest/autorun'
require_relative 'pythagorean_triplet'

class TripletTest < Minitest::Test
  def test_sum
    assert_equal 12, Triplet.new(3, 4, 5).sum
  end

  def test_product
    skip
    assert_equal 60, Triplet.new(3, 4, 5).product
  end

  def test_pythagorean
    skip
    assert Triplet.new(3, 4, 5).pythagorean?
  end

  def test_not_pythagorean
    skip
    refute Triplet.new(5, 6, 7).pythagorean?
  end

  def test_triplets_upto_10
    skip
    triplets = Triplet.where(max_factor: 10)
    products = triplets.map(&:product).sort
    assert_equal [60, 480], products
  end

  def test_triplets_from_11_upto_20
    skip
    triplets = Triplet.where(min_factor: 11, max_factor: 20)
    products = triplets.map(&:product).sort
    assert_equal [3840], products
  end

  def test_triplets_where_sum_x
    skip
    triplets = Triplet.where(sum: 180, max_factor: 100)
    products = triplets.map(&:product).sort
    assert_equal [118_080, 168_480, 202_500], products
  end
end