1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
3 class AboutArrays < EdgeCase::Koan
4 def test_creating_arrays
5 empty_array = Array.new
6 assert_equal __, empty_array.class
7 assert_equal __, empty_array.size
10 def test_array_literals
12 assert_equal [], array
15 assert_equal [1], array
18 assert_equal [1, __], array
21 assert_equal __, array
24 def test_accessing_array_elements
25 array = [:peanut, :butter, :and, :jelly]
27 assert_equal __, array[0]
28 assert_equal __, array.first
29 assert_equal __, array[3]
30 assert_equal __, array.last
31 assert_equal __, array[-1]
32 assert_equal __, array[-3]
35 def test_slicing_arrays
36 array = [:peanut, :butter, :and, :jelly]
38 assert_equal __, array[0,1]
39 assert_equal __, array[0,2]
40 assert_equal __, array[2,2]
41 assert_equal __, array[2,20]
42 assert_equal __, array[4,0]
43 assert_equal __, array[4,100]
44 assert_equal __, array[5,0]
47 def test_arrays_and_ranges
48 assert_equal __, (1..5).class
49 assert_not_equal [1,2,3,4,5], (1..5)
50 assert_equal __, (1..5).to_a
51 assert_equal __, (1...5).to_a
54 def test_slicing_with_ranges
55 array = [:peanut, :butter, :and, :jelly]
57 assert_equal __, array[0..2]
58 assert_equal __, array[0...2]
59 assert_equal __, array[2..-1]
62 def test_pushing_and_popping_arrays
66 assert_equal __, array
68 popped_value = array.pop
69 assert_equal __, popped_value
70 assert_equal __, array
73 def test_shifting_arrays
77 assert_equal __, array
79 shifted_value = array.shift
80 assert_equal __, shifted_value
81 assert_equal __, array