./test/tc_array.rb in extensions-0.5.0 vs ./test/tc_array.rb in extensions-0.6.0
- old
+ new
@@ -21,7 +21,27 @@
assert_equal([0,1,2,3], a, "select all")
a = [0,1,2,3]
assert_equal([], a.select! {false}, "select none")
assert_equal([], a, "select none")
end
+
+ def test_only
+ assert_equal(5, [5].only)
+ assert_equal(nil, [nil].only)
+ assert_raise(IndexError) { [].only }
+ assert_raise(IndexError) { [1,2,3].only }
+ end
+
+ def test_rand
+ array = [1,2,3]
+ seen = Hash.new { |hash, key| hash[key] = 0 }
+ 1000.times do
+ n = array.rand
+ seen[n] += 1
+ end
+ assert_equal([1,2,3], seen.keys.sort)
+ assert(seen[1] > 100)
+ assert(seen[2] > 100)
+ assert(seen[3] > 100)
+ end
end # class TC_Array