aboutsummaryrefslogtreecommitdiff
path: root/challenge-086/roger-bell-west/ruby/ch-1.rb
blob: 66d544a74b0c9172d0fcca95acd4fa711bb58444 (plain)
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
#! /usr/bin/ruby

require 'set'

def pti(n,a)
  ns=Set.new(n)
  n.each do |x|
    if ns.include?(x+a)
      return 1
    end
  end
  return 0
end

require 'test/unit'

class TestPti < Test::Unit::TestCase

    def test_ex1
      assert_equal(1,pti([10, 8, 12, 15, 5],7))
    end

    def test_ex2
      assert_equal(1,pti([1, 5, 2, 9, 7],6))
    end

    def test_ex3
      assert_equal(0,pti([10, 30, 20, 50, 40],15))
    end

end