# skalnik/euler

Cleaned up the testing suite, and added Rudoku tests.

Nick Kezhaya committed Oct 12, 2009
1 parent d1dc774 commit fe973a5eb78ac943bdd4da1cd6c3e4990b5b701a
Showing with 35 additions and 6 deletions.
1. +1 −1 lib/euler.rb
2. +2 −2 test/tc_integer_methods.rb
3. +2 −2 test/tc_module.rb
4. +28 −0 test/tc_rudoku.rb
5. +2 −1 test/test_euler.rb
 @@ -187,7 +187,7 @@ def find_missing_pyth_value(a, b, c) # [0, 0, 5, 0, 1, 0, 3, 0, 0]] # ) # => [[4, 8, 3, 9, 2, 1, 6, 5, 7], [9, 6, 7, 3, 4, 5, 8, 2, 1], [2, 5, 1, 8, 7, 6, 4, 9, 3], [5, 4, 8, 1, 3, 2, 9, 7, 6], [7, 2, 9, 5, 6, 4, 1, 3, 8], [1, 3, 6, 7, 9, 8, 2, 4, 5], [3, 7, 2, 6, 8, 9, 5, 1, 4], [8, 1, 4, 2, 5, 3, 7, 6, 9], [6, 9, 5, 4, 1, 7, 3, 8, 2]] def solve_sudoku(puzzle) - require 'rudoku' + require File.dirname(__FILE__) + "/rudoku" rudoku = Rudoku.new(puzzle) rudoku.backtrack_solve rudoku.to_a
 @@ -1,6 +1,6 @@ require "test/unit" -require "euler" +require File.dirname(__FILE__) + "/../lib/euler" class TestIntegerMethods < Test::Unit::TestCase def test_factorial @@ -42,4 +42,4 @@ 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 +end
 @@ -1,6 +1,6 @@ require "test/unit" -require "euler" +require File.dirname(__FILE__) + "/../lib/euler" class TestModule < Test::Unit::TestCase def test_sieve @@ -37,4 +37,4 @@ def test_find_missing_pyth_value assert_equal(4, Euler.find_missing_pyth_value(3, nil, 5)) assert_equal(5, Euler.find_missing_pyth_value(3, 4, nil)) end -end +end
 @@ -0,0 +1,28 @@ +require "test/unit" + +require File.dirname(__FILE__) + "/../lib/euler" + +class TestRudoku < Test::Unit::TestCase + def test_rudoku + assert_equal([[4, 8, 3, 9, 2, 1, 6, 5, 7], + [9, 6, 7, 3, 4, 5, 8, 2, 1], + [2, 5, 1, 8, 7, 6, 4, 9, 3], + [5, 4, 8, 1, 3, 2, 9, 7, 6], + [7, 2, 9, 5, 6, 4, 1, 3, 8], + [1, 3, 6, 7, 9, 8, 2, 4, 5], + [3, 7, 2, 6, 8, 9, 5, 1, 4], + [8, 1, 4, 2, 5, 3, 7, 6, 9], + [6, 9, 5, 4, 1, 7, 3, 8, 2]], + Euler.solve_sudoku([[0, 0, 3, 0, 2, 0, 6, 0, 0], + [9, 0, 0, 3, 0, 5, 0, 0, 1], + [0, 0, 1, 8, 0, 6, 4, 0, 0], + [0, 0, 8, 1, 0, 2, 9, 0, 0], + [7, 0, 0, 0, 0, 0, 0, 0, 8], + [0, 0, 6, 7, 0, 8, 2, 0, 0], + [0, 0, 2, 6, 0, 9, 5, 0, 0], + [8, 0, 0, 2, 0, 3, 0, 0, 9], + [0, 0, 5, 0, 1, 0, 3, 0, 0]] + ) + ) + end +end
 @@ -1,4 +1,5 @@ #!/usr/bin/env ruby require 'test/unit/testsuite' require 'tc_integer_methods.rb' -require 'tc_module.rb' +require 'tc_module.rb' +require 'tc_rudoku.rb'