Sha256: 7f8a3fa221ba91bdaacb716afa4d8f21c3c22700f55b39927e4eea5dc45965d9
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 KB
Contents
require "test/unit" require File.dirname(__FILE__) + "/../lib/euler" class TestIntegerMethods < Test::Unit::TestCase def test_factorial assert_equal(1, 0.factorial, "0! == 1") assert_equal(1, 1.factorial, "1! == 1") assert_equal(120, 5.factorial, "5! == 120") end def test_prime_factors assert_equal([2, 5], 10.prime_factors, "10 factors into 2 and 5.") assert_equal([2, 2, 5], 20.prime_factors, "20 factors into 2, 2, and 5.") assert_equal([2, 2, 7, 23], 644.prime_factors, "644 factors into 2, 2, 7, and 23.") end def test_primality assert(!1.prime?, "1 is not a prime.") assert(2.prime?, "2 is the first prime.") assert(3.prime?, "3 is the second prime.") assert(29.prime?, "29 is the tenth prime.") assert(!77.prime?, "77 is not a prime.") end def test_permutations assert(132.is_permutation?(123), "132 is a permutation of 123.") assert(!3344.is_permutation?(3444), "3344 is not a permutation of 3444.") end def test_pandigitial assert(1234567890.is_pandigital?(0..9), "124567890 is a 0 to 9 pandigital.") assert(!123456789.is_pandigital?(0..9), "12346789 is not a 0 to 9 pandigital."); end def test_fibonacci assert(1.is_fibonacci?, "1 is the first & second fibonacci numbers") assert(8.is_fibonacci?, "8 is the sixth fibonacci number") end def test_length assert_equal(2, 10.length, "10 has a length of 2") assert_equal(4, 4563.length, "4563 has a length of 4") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
euler-1.1.0 | test/tc_integer_methods.rb |