Beispiel #1
0
	def testId(self):

		# valid calls
		DcmtRandom(id=20, gen_seed=1)
		DcmtRandom.range(1, 4, gen_seed=1)
		DcmtRandomState(id=3000, gen_seed=1)
		DcmtRandomState.range(100, 103, gen_seed=1)
		mt_range(4, gen_seed=1)

		# check that range functions behave like Python range()
		for func in (DcmtRandom.range, DcmtRandomState.range, mt_range):
			for args in ((), (1, 2, 3)):
				self.assertRaises(TypeError, func, *args)

			self.assertEqual(func(3, 1), [])

		# error: id < 0
		self.assertRaises(DcmtParameterError, DcmtRandom, id=-1, gen_seed=1)
		self.assertRaises(DcmtParameterError, DcmtRandom.range, -1, 3, gen_seed=1)
		self.assertRaises(DcmtParameterError, DcmtRandomState, id=-1, gen_seed=1)
		self.assertRaises(DcmtParameterError, DcmtRandomState.range, -1, 2, gen_seed=1)
		self.assertRaises(DcmtParameterError, mt_range, -1, 3, gen_seed=1)

		# error: id > 65535
		self.assertRaises(DcmtParameterError, DcmtRandom, id=65536, gen_seed=1)
		self.assertRaises(DcmtParameterError, DcmtRandom.range, 65535, 65537, gen_seed=1)
		self.assertRaises(DcmtParameterError, DcmtRandomState, id=65536, gen_seed=1)
		self.assertRaises(DcmtParameterError, DcmtRandomState.range, 65535, 65537, gen_seed=1)
		self.assertRaises(DcmtParameterError, mt_range, 65534, 65539, gen_seed=1)
		self.assertRaises(DcmtParameterError, mt_range, 65536, 65539, gen_seed=1)
Beispiel #2
0
    def testId(self):

        # valid calls
        DcmtRandom(id=20, gen_seed=1)
        DcmtRandom.range(1, 4, gen_seed=1)
        DcmtRandomState(id=3000, gen_seed=1)
        DcmtRandomState.range(100, 103, gen_seed=1)
        mt_range(4, gen_seed=1)

        # check that range functions behave like Python range()
        for func in (DcmtRandom.range, DcmtRandomState.range, mt_range):
            for args in ((), (1, 2, 3)):
                self.assertRaises(TypeError, func, *args)

            self.assertEqual(func(3, 1), [])

        # error: id < 0
        self.assertRaises(DcmtParameterError, DcmtRandom, id=-1, gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          DcmtRandom.range,
                          -1,
                          3,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          DcmtRandomState,
                          id=-1,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          DcmtRandomState.range,
                          -1,
                          2,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError, mt_range, -1, 3, gen_seed=1)

        # error: id > 65535
        self.assertRaises(DcmtParameterError, DcmtRandom, id=65536, gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          DcmtRandom.range,
                          65535,
                          65537,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          DcmtRandomState,
                          id=65536,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          DcmtRandomState.range,
                          65535,
                          65537,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          mt_range,
                          65534,
                          65539,
                          gen_seed=1)
        self.assertRaises(DcmtParameterError,
                          mt_range,
                          65536,
                          65539,
                          gen_seed=1)
Beispiel #3
0
	def testGetrandbits(self):
		rng = DcmtRandom(gen_seed=55)
		rng.seed(555)
		stop = 2 ** 64

		randoms = numpy.array([float(rng.randrange(0, stop)) for i in xrange(1000)])

		diff_mean, diff_var = testLimits(randoms, 0, stop)

		self.assert_(diff_mean < 0.05)
		self.assert_(diff_var < 0.05)
Beispiel #4
0
    def testGetrandbits(self):
        rng = DcmtRandom(gen_seed=55)
        rng.seed(555)
        stop = 2**64

        randoms = numpy.array(
            [float(rng.randrange(0, stop)) for i in xrange(1000)])

        diff_mean, diff_var = testLimits(randoms, 0, stop)

        self.assert_(diff_mean < 0.05)
        self.assert_(diff_var < 0.05)