"""
Copyright 2015-2016 Peter Urda

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from random import Random
from unittest import TestCase

from nistbeacon import NistBeaconValue
from tests.test_data.nist_records import local_record_db


class TestPseudoRandom(TestCase):
    @classmethod
    def setUpClass(cls):
        cls.init_record = local_record_db[1378395540]
        cls.sample_record = local_record_db[1447873020]

    def test_pseudo_random(self):
        """
        Check the seeding of NistBeaconValue's pseudo random property
        """

        init = NistBeaconValue.from_json(self.init_record.json)
        sample = NistBeaconValue.from_xml(self.sample_record.xml)

        # Basic object checking
        self.assertIsInstance(init, NistBeaconValue)
        self.assertIsInstance(sample, NistBeaconValue)

        self.assertIsInstance(init.pseudo_random, Random)
        self.assertIsInstance(sample.pseudo_random, Random)
        self.assertIsNot(
            init.pseudo_random,
            sample.pseudo_random,
        )

        # Verify that the pseudo random was seeded correctly
        # Init record check
        self.assertEqual(
            init.pseudo_random.random(),
            0.6461135178195806,
        )

        self.assertEqual(
            init.pseudo_random.uniform(100, 1000),
            973.057931801389,
        )

        self.assertEqual(
            init.pseudo_random.randrange(53, 350),
            230,
        )

        self.assertEqual(
            init.pseudo_random.randint(1000, 9999),
            4596,
        )

        # Sample value check
        self.assertEqual(
            sample.pseudo_random.random(),
            0.9150597089635818,
        )

        self.assertEqual(
            sample.pseudo_random.uniform(100, 1000),
            416.46104853317524,
        )

        self.assertEqual(
            sample.pseudo_random.randrange(53, 350),
            118,
        )

        self.assertEqual(
            sample.pseudo_random.randint(1000, 9999),
            7526,
        )

@@ -913,29 +913,41 @@
 ef test_
-pseudo_random
+init_record_random_values
 (self):%0A
@@ -1031,85 +1031,56 @@
 erty
-%0A        %22%22%22%0A%0A        init = NistBeaconValue.from_json(self.init_
+.%0A%0A        This is for the known initial 
 record.
-json)
 %0A   
@@ -1088,151 +1088,47 @@
     
-sample = NistBeaconValue.from_xml(self.sample_record.xml)%0A%0A        # Basic object checking%0A        self.assertIsInstance(init, NistBeaconValue)
+%22%22%22%0A%0A        record = self.init_record%0A
 %0A   
@@ -1154,22 +1154,22 @@
 nstance(
-sample
+record
 , NistBe
@@ -1179,17 +1179,16 @@
 nValue)%0A
-%0A
         
@@ -1213,196 +1213,36 @@
 nce(
-init.pseudo_random, Random)%0A        self.assertIsInstance(sample.pseudo_random, Random)%0A        self.assertIsNot(%0A            init.pseudo_random,%0A            sample.pseudo_random,%0A        
+record.pseudo_random, Random
 )%0A%0A 
@@ -1305,36 +1305,8 @@
 tly%0A
-        # Init record check%0A
     
@@ -1331,36 +1331,38 @@
 al(%0A            
-init
+record
 .pseudo_random.r
@@ -1443,36 +1443,38 @@
 al(%0A            
-init
+record
 .pseudo_random.u
@@ -1563,36 +1563,38 @@
 al(%0A            
-init
+record
 .pseudo_random.r
@@ -1678,20 +1678,22 @@
         
-init
+record
 .pseudo_
@@ -1757,32 +1757,410 @@
     
-    # Sample value check
+def test_sample_record_random_values(self):%0A        %22%22%22%0A        Check the seeding of NistBeaconValue's pseudo random property%0A%0A        This is for the reference testing record%0A        %22%22%22%0A%0A        record = self.sample_record%0A%0A        self.assertIsInstance(record, NistBeaconValue)%0A        self.assertIsInstance(record.pseudo_random, Random)%0A%0A        # Verify that the pseudo random was seeded correctly
 %0A   
@@ -2186,38 +2186,38 @@
 al(%0A            
-sample
+record
 .pseudo_random.r
@@ -2298,38 +2298,38 @@
 al(%0A            
-sample
+record
 .pseudo_random.u
@@ -2420,38 +2420,38 @@
 al(%0A            
-sample
+record
 .pseudo_random.r
@@ -2535,22 +2535,22 @@
         
-sample
+record
 .pseudo_

Split the pseudo_random tests up