Sha256: d486342bb002f75befb39f967815fd962a72f979924eb6eaad345d47eccd79db

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# coding: utf-8

#==============================================================================#
# $Id: test_rand.rb 108 2009-02-09 06:04:39Z yuyakato $
#==============================================================================#

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.0.9 test/test_rand.rb