1
exercism fetch ruby list-ops

list_ops_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'minitest/autorun'
require_relative 'list_ops'

class ListOpsTest < Minitest::Test
  def test_count_empty
    assert_equal 0, ListOps.arrays([])
  end

  def test_count_normal
    skip
    assert_equal 5, ListOps.arrays(Array.new(5))
  end

  def test_count_gigantic
    skip
    assert_equal 1_000_000, ListOps.arrays(Array.new(1_000_000))
  end

  def test_reverse_empty
    skip
    assert_equal [], ListOps.reverser([])
  end

  def test_reverse_normal
    skip
    assert_equal [5, 4, 3, 2, 1], ListOps.reverser([1, 2, 3, 4, 5])
  end

  def test_reverse_gigantic
    skip
    expected = (1..1_000_000).to_a.reverse
    assert_equal expected, ListOps.reverser((1..1_000_000).to_a)
  end

  def test_concat_empty
    skip
    assert_equal [], ListOps.concatter([], [])
  end

  def test_concat_normal
    skip
    assert_equal [12, 34, 56, 78], ListOps.concatter([12, 34], [56, 78])
  end

  def test_concat_gigantic
    skip
    input1 = (1..1_000_000).to_a
    input2 = (1_000_001..2_000_000).to_a
    assert_equal (1..2_000_000).to_a, ListOps.concatter(input1, input2)
  end

  def test_mapper_empty
    skip
    assert_equal [], ListOps.mapper([])
  end

  def test_mapper_normal
    skip
    assert_equal [2, 3, 4, 5, 6], ListOps.mapper([1, 2, 3, 4, 5]) { |n| n + 1 }
  end

  def test_mapper_gigantic
    skip
    result = ListOps.mapper((1..1_000_000).to_a) { |n| n + 1 }
    assert_equal (2..1_000_001).to_a, result
  end

  def test_filterer_empty
    skip
    assert_equal [], ListOps.filterer([])
  end

  def test_filterer_normal
    skip
    result = ListOps.filterer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], &:odd?)
    assert_equal [1, 3, 5, 7, 9], result
  end

  def test_filterer_gigantic
    skip
    result = ListOps.filterer((1..10_000).to_a, &:even?)
    assert_equal (1..10_000).to_a.select(&:even?), result
  end

  def test_sum_reducer_empty
    skip
    assert_equal 0, ListOps.sum_reducer([])
  end

  def test_sum_reducer_normal
    skip
    assert_equal 55, ListOps.sum_reducer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  end

  def test_factorial_reducer_empty
    skip
    assert_equal 1, ListOps.factorial_reducer([])
  end

  def test_factorial_reducer_normal
    skip
    input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    assert_equal 3_628_800, ListOps.factorial_reducer(input)
  end

  def test_bookkeeping
    skip
    assert_equal 2, BookKeeping::VERSION
  end
end