Add specs

This commit is contained in:
Alex Clink 2022-01-22 23:43:34 -05:00
parent 686c6bd006
commit 5456adad4e
2 changed files with 50 additions and 9 deletions

View file

@ -36,6 +36,13 @@ describe Matrix do
result = mat * ident
result.should eq(mat)
end
it "multiplies different types" do
m1 = Matrix[1, 2, 3, 4]
m2 = Matrix[2.0, 0.0, 0.0, 2.0]
m3 = Matrix[2.0, 4.0, 6.0, 8.0]
(m1 * m2).should eq(m3)
end
end
describe "#size" do
@ -45,18 +52,32 @@ describe Matrix do
3, 4,
]
mat.size.should eq(2)
mat.width.should eq(2)
end
end
it "raises an exception if called on a non-square matrix" do
mat = Matrix(Int32, 2, 4).new(Slice[
1, 2,
3, 4,
5, 6,
7, 8,
])
describe "#==" do
it "accurately show equality" do
m1 = Matrix[
1, 1, 1,
1, 1, 1,
1, 1, 1,
]
expect_raises(Exception, "Matrix(2x4) is not square") { mat.size }
m2 = Matrix[
1, 1, 1,
1, 1, 1,
1, 1, 1,
]
m3 = Matrix[
2, 2, 2,
2, 2, 2,
2, 2, 2,
]
(m1 == m2).should eq(true)
(m1 == m3).should eq(false)
end
end
end

20
spec/transform2d_spec.cr Normal file
View file

@ -0,0 +1,20 @@
require "./spec_helper"
require "../src/transform2d"
include PF
describe Transform2d do
describe "#translate" do
it "creates the same matrix as matrix multiplication" do
t = Transform2d.new
t.translate(-1.0, -2.0).rotate(0.5).scale(1.1).translate(1.0, 2.0)
m = Transform2d.translation(-1.0, -2.0)
m = Transform2d.rotation(0.5) * m
m = Transform2d.scale(1.1, 1.1) * m
m = Transform2d.translation(1.0, 2.0) * m
t.matrix.should eq(m)
end
end
end