- Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmissing_integer.rb
More file actions
Latest commit
41 lines (30 loc) · 709 Bytes
/
Copy pathmissing_integer.rb
File metadata and controls
41 lines (30 loc) · 709 Bytes
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
# https://codility.com/demo/take-sample-test/missing_integer
defmissing_integer(a)
seen={}
a.eachdo |number|
seen[number]=true
end
max=a.max
foriin1..(max + 1)
returniunlessseen[i]
end
1
end
require'minitest/autorun'
classTests < MiniTest::Unit::TestCase
deftest_example_input
assert_equal5,missing_integer([1,3,6,4,1,2])
end
deftest_all_negative
assert_equal1,missing_integer([-1, -10, -2, -3, -1])
end
deftest_one_element
assert_equal2,missing_integer([1])
end
deftest_one_element_2
assert_equal1,missing_integer([3])
end
deftest_last_is_missing
assert_equal4,missing_integer([1,2,1,3])
end
end