Created
September 15, 2019 13:34
-
-
Save mame-n/6bc94f397d68570f710acd29fc015f4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test/unit" | |
require "pp" | |
require "./p101.rb" | |
class TC < Test::Unit::TestCase | |
def setup | |
# @eq = 1 # 1 is debug mode. Equation is un=n**3 | |
@eq = 0 | |
@o = P101.new( @eq ) | |
end | |
def test_main | |
if @eq == 1 | |
assert_equal( 74, @o.main(3) ) | |
else | |
assert_equal( 37076114526, @o.main ) | |
end | |
end | |
def test_polynomial | |
assert_equal( [7/1r,-6/1r], @o.polynomial( 2 ) ) | |
assert_equal( [6/1r,-11/1r,6/1r], @o.polynomial( 3 )) | |
end | |
def test_bop | |
(2..11).each do |m| | |
puts "#{m} : #{@o.bop( @o.polynomial( m ) )}" | |
end | |
assert_equal( 15, @o.bop( [7/1r,-6/1r] ) ) | |
assert_equal( 58, @o.bop( [6/1r,-11/1r,6/1r] ) ) | |
end | |
def test_solve_equation | |
a3 = [ | |
[1/1r,1/1r,1/1r,1/1r], | |
[0/1r,1/1r,3/2r,-2/1r], | |
[0/1r,0/1r,1/1r,6/1r], | |
] | |
assert_equal([6/1r,-11/1r,6/1r], @o.solve_equation( a3 ) ) | |
end | |
def test_sum_array | |
m1 = [0,1,20] | |
m2 = [5] | |
assert_equal( 100, @o.sum_array( m1, m2 ) ) | |
m1 = [0,1,4,8] | |
m2 = [5,2] | |
assert_equal( 36, @o.sum_array( m1, m2 ) ) | |
m1 = [0/1r,1/1r,1/1r,1/1r] | |
m2 = [-11/1r,6/1r] | |
assert_equal( -5/1r, @o.sum_array( m1, m2 ) ) | |
end | |
def test_bopdum | |
assert_equal( [1], @o.solve_equation( @o.row_reduction( @o.make_matrix(1) ) ) ) | |
assert_equal( [7/1r,-6/1r], @o.solve_equation( @o.row_reduction( @o.make_matrix(2) ) ) ) | |
assert_equal( [6/1r,-11/1r,6/1r], @o.solve_equation( @o.row_reduction( @o.make_matrix(3) ) ) ) | |
end | |
def test_make_matrix | |
if @eq == 1 | |
ans2 = [ | |
[1,1,1], | |
[2,1,8]] | |
ans3 = [ | |
[1,1,1,1], | |
[4,2,1,8], | |
[9,3,1,27]] | |
ans4 = [ | |
[1,1,1,1,1], | |
[8,4,2,1,8], | |
[27,9,3,1,27], | |
[64,16,4,1,64]] | |
else | |
ans2 = [ | |
[1,1,1], | |
[2,1,8] | |
] | |
ans3 = [ | |
[1,1,1,1], | |
[4,2,1,8], | |
[9,3,1,44287] | |
] | |
ans4 = [ | |
[1,1,1,1,1], | |
[8,4,2,1,8], | |
[27,9,3,1,44287], | |
[64,16,4,1,838861] | |
] | |
end | |
assert_equal( ans2, @o.make_matrix( 2 ) ) | |
assert_equal( ans3, @o.make_matrix( 3 ) ) | |
assert_equal( ans4, @o.make_matrix( 4 ) ) | |
end | |
def test_uns | |
if @eq == 1 | |
ans = [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331] | |
else | |
ans = [ | |
1, | |
683, | |
44287, | |
838861, | |
8138021, | |
51828151, | |
247165843, | |
954437177, | |
3138105961, | |
9090909091, | |
23775972551] | |
end | |
assert_equal( ans, @o.uns ) | |
end | |
def test_anns | |
ans2 = [ | |
[1,1], | |
[2,1]] | |
assert_equal( ans2, @o.anns( 2 ) ) | |
ans3 = [ | |
[1,1,1], | |
[4,2,1], | |
[9,3,1]] | |
assert_equal( ans3, @o.anns( 3 ) ) | |
ans4 = [ | |
[1,1,1,1], | |
[8,4,2,1], | |
[27,9,3,1], | |
[64,16,4,1]] | |
assert_equal( ans4, @o.anns( 4 ) ) | |
end | |
def test_row_reduction | |
a3 = [ | |
[1/1r,1/1r,1/1r,1/1r], | |
[4,2,1,8], | |
[9,3,1,27], | |
] | |
ans3 = [ | |
[1/1r,1/1r,1/1r,1/1r], | |
[0/1r,1/1r,3/2r,-2/1r], | |
[0/1r,0/1r,1/1r,6/1r], | |
] | |
assert_equal( ans3, @o.row_reduction( a3 ) ) | |
a4 = [ | |
[1/1r,1/1r,1/1r,1/1r,1/1r], | |
[8,4,2,1,8], | |
[27,9,3,1,27], | |
[64,16,4,1,64] | |
] | |
ans4 = [ | |
[1/1r,1/1r,1/1r,1/1r,1/1r], | |
[0/1r,1/1r,3/2r,7/4r,0/1r], | |
[0/1r,0/1r,1/1r,11/6r,0/1r], | |
[0/1r,0/1r,0/1r,1/1r,0/1r] | |
] | |
assert_equal( ans4, @o.row_reduction( a4, 0 ) ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment