Sha256: 61dd41a812ac30be7fa1bd370143529932f579399e2ef7ad2d97a1da6df6a66e

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

require_relative 'helper'


class TestBitmap < Test::Unit::TestCase

  W = 32
  H = 16

  def bitmap(w = W, h = H)
    Rays::Bitmap.new w, h
  end

  def color(*args)
    Rays::Color.new(*args)
  end

  def test_initialize()
    assert_equal W, bitmap.width
    assert_equal H, bitmap.height
  end

  def test_dup()
    o          = bitmap
    assert_equal color(0, 0, 0, 0), o[0, 0]
    o[0, 0]    = color(1, 0, 0, 0)
    assert_equal color(1, 0, 0, 0), o[0, 0]
    x          = o.dup
    assert_equal color(1, 0, 0, 0), x[0, 0]
    x[0, 0]    = color(0, 1, 0, 0)
    assert_equal color(0, 1, 0, 0), x[0, 0]
    assert_equal color(1, 0, 0, 0), o[0, 0]
  end

  def test_at()
    o       = bitmap
    assert_equal color(0, 0, 0, 0), o[0, 0]

    o[0, 0] =          1
    assert_equal color(1, 1, 1, 1), o[0, 0]

    o[0, 0] =         [0, 1, 0]
    assert_equal color(0, 1, 0, 1), o[0, 0]

    o[0, 0] =         [0, 1, 0, 0]
    assert_equal color(0, 1, 0, 0), o[0, 0]

    o[0, 0] =    color(0, 0, 1)
    assert_equal color(0, 0, 1, 1), o[0, 0]

    o[0, 0] =    color(0, 0, 1, 0)
    assert_equal color(0, 0, 1, 0), o[0, 0]
  end

  def test_to_a()
    colors = %w[#f00 #0f0 #00f #ff0].map {|s| color s}
    bmp = bitmap 2, 2
    bmp[0, 0], bmp[1, 0], bmp[0, 1], bmp[1, 1] = colors
    assert_equal colors, bmp.to_a
  end

end# TestBitmap

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rays-0.1.46 test/test_bitmap.rb
rays-0.1.45 test/test_bitmap.rb
rays-0.1.44 test/test_bitmap.rb
rays-0.1.43 test/test_bitmap.rb
rays-0.1.42 test/test_bitmap.rb
rays-0.1.40 test/test_bitmap.rb