[cairo-commit] rcairo/test test_paper.rb,1.2,1.3

Kouhei Sutou commit at pdx.freedesktop.org
Thu Apr 10 19:34:26 PDT 2008


Committed by: kou

Update of /cvs/cairo/rcairo/test
In directory kemper:/tmp/cvs-serv18724/test

Modified Files:
	test_paper.rb 
Log Message:
* src/lib/cairo/paper.rb, test/test_paper.rb: use pt as default unit.


Index: test_paper.rb
===================================================================
RCS file: /cvs/cairo/rcairo/test/test_paper.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_paper.rb	9 Apr 2008 06:28:54 -0000	1.2
+++ test_paper.rb	11 Apr 2008 02:39:12 -0000	1.3
@@ -24,10 +24,10 @@
 
   def test_parse_size
     assert_parse(paper(100, 200), "100x200")
-    assert_parse(paper(100, 200), "100mmx200mm")
-    assert_parse(paper(100.5, 200.9), "100.5mmx200.9")
-    assert_parse(paper(100.5, 200.9), "100.5mmx200.9")
-    assert_parse(paper(25.4, 215.9), "1inchx8.5inch")
+    assert_parse(paper(283.46456664, 566.929134), "100mmx200mm")
+    assert_parse(paper(284.88188952, 200.9), "100.5mmx200.9")
+    assert_parse(paper(72, 612.0), "1inx8.5inch")
+    assert_parse(paper(28.346456664, 24094.488168), "1cmx8.5m")
     assert_parse(paper(100, 200), [100, 200])
 
     exception = assert_raise(Cairo::Paper::UnknownUnit) do
@@ -47,14 +47,47 @@
     assert_equal({}, exception.description)
   end
 
+  def test_unit
+    paper = parse("1cmx8.5m")
+    assert_nil(paper.unit)
+    assert_in_delta(28.346456664, 0.01, paper.width)
+    assert_in_delta(24094.488168, 0.01, paper.height)
+
+    paper.unit = "inch"
+    assert_equal("inch", paper.unit)
+    assert_in_delta(0.393700787, 0.01, paper.width)
+    assert_in_delta(334.645669, 0.01, paper.height)
+  end
+
   private
   def paper(width, height)
     Cairo::Paper.new(width, height)
   end
 
-  def assert_parse(expected, paper_description)
+  def parse(paper_description)
+    Cairo::Paper.parse(paper_description)
+  end
+
+  def assert_parse(expected, paper_description, message=nil)
     expected = Cairo::Paper.const_get(expected) if expected.is_a?(Symbol)
-    actual_paper = Cairo::Paper.parse(paper_description)
-    assert_equal(expected.to_s, actual_paper.nil? ? nil : actual_paper.to_s)
+    actual_paper = parse(paper_description)
+    assert_equal_paper(expected, actual_paper, message)
+  end
+
+  def assert_equal_paper(expected, actual, message=nil)
+    delta = 0.01
+    assert_block(build_message(message,
+                               "<?> expected but was\n<?>.",
+                               expected, actual)) do
+      if actual.nil?
+        expected.nil?
+      else
+        (expected.width - delta < actual.width and
+         actual.width < expected.width + delta) and
+          (expected.height - delta < actual.height and
+           actual.height < expected.height + delta) and
+          expected.name == actual.name
+      end
+    end
   end
 end



More information about the cairo-commit mailing list