Exemple #1
0
    def test_load_save(self):
        rng = RandomNumberGenerator()
        with self.assertRaises(IOError):
            rng.loadState("does/not/exist")

        with TestAreaContext("rng_state") as t:
            rng.saveState( "rng.txt" )
            t.sync()
            val1 = rng.getInt()
            val2 = rng.getInt()
            rng.loadState( "rng.txt" )
            self.assertEqual( rng.getInt() , val1 )
            self.assertEqual( rng.getInt() , val2 )
Exemple #2
0
    def test_rng_state(self):
        rng = RandomNumberGenerator()        
        with self.assertRaises(ValueError):
            rng.setState("12")
        
        rng.setState("0123456789ABCDEF")
        val1 = rng.getInt()
        val2 = rng.getInt()

        self.assertFalse( val1 == val2 )
        rng.setState("0123456789ABCDEF")
        self.assertEqual( rng.getInt() , val1)
        self.assertEqual( rng.getInt() , val2)
Exemple #3
0
    def test_rng_state(self):
        rng = RandomNumberGenerator()        
        with self.assertRaises(ValueError):
            rng.setState("12")
        
        rng.setState("0123456789ABCDEF")
        val1 = rng.getInt()
        val2 = rng.getInt()

        self.assertFalse( val1 == val2 )
        rng.setState("0123456789ABCDEF")
        self.assertEqual( rng.getInt() , val1)
        self.assertEqual( rng.getInt() , val2)
Exemple #4
0
    def test_load_save(self):
        rng = RandomNumberGenerator()
        with self.assertRaises(IOError):
            rng.loadState("does/not/exist")

        with TestAreaContext("rng_state") as t:
            rng.saveState("rng.txt")
            t.sync()
            val1 = rng.getInt()
            val2 = rng.getInt()
            rng.loadState("rng.txt")
            self.assertEqual(rng.getInt(), val1)
            self.assertEqual(rng.getInt(), val2)