]> gitweb.factorcode.org Git - factor.git/commitdiff
images.gif: added unit tests
authorKeith Lazuka <klazuka@gmail.com>
Wed, 23 Sep 2009 16:06:49 +0000 (12:06 -0400)
committerKeith Lazuka <klazuka@gmail.com>
Wed, 23 Sep 2009 16:06:49 +0000 (12:06 -0400)
extra/images/gif/gif-tests.factor [new file with mode: 0644]
extra/images/testing/check-256-colors.gif [new file with mode: 0644]
extra/images/testing/monochrome.gif [new file with mode: 0644]
extra/images/testing/symbol-word-16-colors.gif [new file with mode: 0644]

diff --git a/extra/images/gif/gif-tests.factor b/extra/images/gif/gif-tests.factor
new file mode 100644 (file)
index 0000000..1c4a801
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2009 Keith Lazuka.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors images.gif io io.encodings.binary io.files
+math namespaces sequences tools.test math.bitwise ;
+IN: images.gif.tests
+
+: path>gif ( path -- loading-gif )
+    binary [ input-stream get load-gif ] with-file-reader ;
+
+: gif-example1 ( -- loading-gif )
+    "resource:extra/images/testing/symbol-word-16-colors.gif" path>gif ;
+
+: gif-example2 ( -- loading-gif )
+    "resource:extra/images/testing/check-256-colors.gif" path>gif ;
+
+: gif-example3 ( -- loading-gif )
+    "resource:extra/images/testing/monochrome.gif" path>gif ;
+
+: declared-num-colors ( gif -- n ) flags>> 3 bits 1 + 2^ ;
+: actual-num-colors ( gif -- n ) global-color-table>> length 3 /i ;
+
+[ 16 ] [ gif-example1 actual-num-colors ] unit-test
+[ 16 ] [ gif-example1 declared-num-colors ] unit-test
+
+[ 256 ] [ gif-example2 actual-num-colors ] unit-test
+[ 256 ] [ gif-example2 declared-num-colors ] unit-test
+
+[ 2 ] [ gif-example3 actual-num-colors ] unit-test
+[ 2 ] [ gif-example3 declared-num-colors ] unit-test
diff --git a/extra/images/testing/check-256-colors.gif b/extra/images/testing/check-256-colors.gif
new file mode 100644 (file)
index 0000000..df83efa
Binary files /dev/null and b/extra/images/testing/check-256-colors.gif differ
diff --git a/extra/images/testing/monochrome.gif b/extra/images/testing/monochrome.gif
new file mode 100644 (file)
index 0000000..de74e65
Binary files /dev/null and b/extra/images/testing/monochrome.gif differ
diff --git a/extra/images/testing/symbol-word-16-colors.gif b/extra/images/testing/symbol-word-16-colors.gif
new file mode 100644 (file)
index 0000000..e097fdc
Binary files /dev/null and b/extra/images/testing/symbol-word-16-colors.gif differ