test/test-mnist.rb in red-datasets-0.0.6 vs test/test-mnist.rb in red-datasets-0.0.7
- old
+ new
@@ -1,101 +1,126 @@
class MNISTTest < Test::Unit::TestCase
- include Helper::Sandbox
-
sub_test_case("Normal") do
- def setup_data
- setup_sandbox
-
- def @dataset.cache_dir_path
- @cache_dir_path
- end
-
- def @dataset.cache_dir_path=(path)
- @cache_dir_path = path
- end
- @dataset.cache_dir_path = @tmp_dir
-
- def @dataset.download(output_path, url)
- image_magic_number = 2051
- label_magic_number = 2049
- n_image, image_size_x, image_size_y, label = 10, 28, 28, 1
-
- Zlib::GzipWriter.open(output_path) do |gz|
- if output_path.basename.to_s.include?("-images-")
- image_data = ([image_magic_number, n_image]).pack('N2') +
- ([image_size_x,image_size_y]).pack('N2') +
- ([0] * image_size_x * image_size_y).pack("C*") * n_image
- gz.puts(image_data)
- else
- label_data = ([label_magic_number, n_image]).pack('N2') +
- ([label] * n_image).pack("C*")
- gz.puts(label_data)
- end
- end
- end
- end
-
- def teardown
- teardown_sandbox
- end
-
sub_test_case("train") do
def setup
@dataset = Datasets::MNIST.new(type: :train)
- setup_data()
end
test("#each") do
- raw_dataset = @dataset.collect do |record|
- {
- :label => record.label,
- :pixels => record.pixels
- }
- end
-
+ records = @dataset.each.to_a
assert_equal([
- {
- :label => 1,
- :pixels => [0] * 28 * 28
- }
- ] * 10,
- raw_dataset)
+ 60000,
+ [
+ 5,
+ 784,
+ [0, 0, 0, 49, 238, 253, 253, 253, 253, 253],
+ [0, 0, 0, 0, 0, 81, 240, 253, 253, 119],
+ ],
+ [8,
+ 784,
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 62],
+ [0, 0, 190, 196, 14, 2, 97, 254, 252, 146],
+ ],
+ ],
+ [
+ records.size,
+ [
+ records[0].label,
+ records[0].pixels.size,
+ records[0].pixels[200, 10],
+ records[0].pixels[400, 10],
+ ],
+ [
+ records[-1].label,
+ records[-1].pixels.size,
+ records[-1].pixels[200, 10],
+ records[-1].pixels[400, 10],
+ ],
+ ])
end
test("#to_table") do
table_data = @dataset.to_table
- assert_equal([[0] * 28 * 28] * 10,
- table_data[:pixels])
+ assert_equal([
+ [0, 0, 0, 49, 238, 253, 253, 253, 253, 253],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 62],
+ ],
+ [
+ table_data[:pixels][0][200, 10],
+ table_data[:pixels][-1][200, 10],
+ ])
end
+
+ sub_test_case("#metadata") do
+ test("#id") do
+ assert_equal("mnist-train", @dataset.metadata.id)
+ end
+
+ test("#name") do
+ assert_equal("MNIST: train", @dataset.metadata.name)
+ end
+ end
end
sub_test_case("test") do
def setup
@dataset = Datasets::MNIST.new(type: :test)
- setup_data()
end
test("#each") do
- raw_dataset = @dataset.collect do |record|
- {
- :label => record.label,
- :pixels => record.pixels
- }
- end
-
+ records = @dataset.each.to_a
assert_equal([
- {
- :label => 1,
- :pixels => [0] * 28 * 28
- }
- ] * 10,
- raw_dataset)
+ 10000,
+ [
+ 7,
+ 784,
+ [0, 0, 84, 185, 159, 151, 60, 36, 0, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 59, 249],
+ ],
+ [
+ 6,
+ 784,
+ [0, 0, 0, 0, 0, 15, 60, 60, 168, 253],
+ [253, 253, 132, 64, 0, 0, 18, 43, 157, 171],
+ ],
+ ],
+ [
+ records.size,
+ [
+ records[0].label,
+ records[0].pixels.size,
+ records[0].pixels[200, 10],
+ records[0].pixels[400, 10],
+ ],
+ [
+ records[-1].label,
+ records[-1].pixels.size,
+ records[-1].pixels[200, 10],
+ records[-1].pixels[400, 10],
+ ],
+ ])
end
test("#to_table") do
table_data = @dataset.to_table
- assert_equal([[0] * 28 * 28] * 10,
- table_data[:pixels])
+ assert_equal([
+ [0, 0, 84, 185, 159, 151, 60, 36, 0, 0],
+ [0, 0, 0, 0, 0, 15, 60, 60, 168, 253],
+ ],
+ [
+ table_data[:pixels][0][200, 10],
+ table_data[:pixels][-1][200, 10],
+ ])
+ end
+
+ sub_test_case("#metadata") do
+ test("#id") do
+ assert_equal("mnist-test", @dataset.metadata.id)
+ end
+
+ test("#name") do
+ assert_equal("MNIST: test", @dataset.metadata.name)
+ end
end
end
end
sub_test_case("Abnormal") do