diff --git a/spec/matrix_spec.cr b/spec/matrix_spec.cr index 509d19a..7a74f71 100644 --- a/spec/matrix_spec.cr +++ b/spec/matrix_spec.cr @@ -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 diff --git a/spec/transform2d_spec.cr b/spec/transform2d_spec.cr new file mode 100644 index 0000000..8cb31d2 --- /dev/null +++ b/spec/transform2d_spec.cr @@ -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