Sha256: 48708cf93b9c90f03a9d836dc628548290b1d73dc716a626e43ca59ed407e8a8

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

# coding: utf-8

require File.dirname(__FILE__) + "/test_helper.rb"
require File.dirname(__FILE__) + "/../lib/kagemusha/rand"

class TestKagemushaRand < Test::Unit::TestCase
  def setup
  end

  def test_always
    musha = Kagemusha::Rand.always(1)
    assert_equal(Kernel, musha.instance_eval { @klass })

    assert_equal([0, 1, 2], (1..100).map { rand(3) }.sort.uniq)

    musha.swap {
      assert_equal(1, rand)
      assert_equal(1, rand(2))
      assert_equal(1, rand(3))
      assert_equal(1, rand(4))
      assert_equal(1, rand(5))
    }

    assert_equal([0, 1, 2], (1..100).map { rand(3) }.sort.uniq)
  end

  def test_always_with_block
    ret = Kagemusha::Rand.always(1) {
      assert_equal(1, rand)
      assert_equal(1, rand(2))
      assert_equal(1, rand(3))
      assert_equal(1, rand(4))
      assert_equal(1, rand(5))
      1
    }

    assert_equal(1, ret)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nayutaya-kagemusha-0.1.0 test/test_rand.rb