Example #1
0
    def test_generategaussians(self):
        '''
        Test if it generates true random numbers from a
        Gaussian distribution (also known as a normal distribution).
        '''
        ret1 = {'message': 'No Random.org api key or api version found.',
                'res': False}
        self.assertDictEqual(random_org.generateGaussians(), ret1)

        ret2 = {'message': 'Required argument, number is missing.',
                'res': False}
        self.assertDictEqual(random_org.generateGaussians(api_key='peW',
                                                          api_version='1'),
                             ret2)

        ret3 = {'message': ('Number of decimal fractions must be'
                            ' between 1 and 10000'), 'res': False}
        self.assertDictEqual(random_org.generateGaussians
                             (api_key='peW', api_version='1',
                              number='5', mean='0.0', standardDeviation='1.0',
                              significantDigits='8'), ret3)

        ret4 = {'message': ("The distribution's mean must be between"
                            " -1000000 and 1000000"), 'res': False}
        self.assertDictEqual(random_org.generateGaussians
                             (api_key='peW', api_version='1', number=5,
                              mean='0.0', standardDeviation='1.0',
                              significantDigits='8'), ret4)

        ret5 = {'message': ("The distribution's standard deviation must be"
                " between -1000000 and 1000000"), 'res': False}
        self.assertDictEqual(random_org.generateGaussians
                             (api_key='peW', api_version='1', number=5,
                              mean=0.0, standardDeviation='1.0',
                              significantDigits='8'), ret5)

        ret6 = {'message': ('The number of significant digits must be'
                ' between 2 and 20'), 'res': False}
        self.assertDictEqual(random_org.generateGaussians
                             (api_key='peW', api_version='1', number=5,
                              mean=0.0, standardDeviation=1.0,
                              significantDigits='8'), ret6)

        ret7 = {'message': u"Parameter 'apiKey' is malformed", 'res': False}
        self.assertDictEqual(random_org.generateGaussians(api_key='peW',
                                                          api_version='1',
                                                          number=5, mean=0.0,
                                                          standardDeviation=1.0,
                                                          significantDigits=8),
                             ret7)
Example #2
0
    def test_generategaussians(self):
        """
        Test if it generates true random numbers from a
        Gaussian distribution (also known as a normal distribution).
        """
        ret1 = {
            "message": "No Random.org api key or api version found.",
            "res": False
        }
        self.assertDictEqual(random_org.generateGaussians(), ret1)

        ret2 = {
            "message": "Required argument, number is missing.",
            "res": False
        }
        self.assertDictEqual(
            random_org.generateGaussians(api_key="peW", api_version="1"), ret2)

        ret3 = {
            "message":
            "Number of decimal fractions must be between 1 and 10000",
            "res": False,
        }
        self.assertDictEqual(
            random_org.generateGaussians(
                api_key="peW",
                api_version="1",
                number="5",
                mean="0.0",
                standardDeviation="1.0",
                significantDigits="8",
            ),
            ret3,
        )

        ret4 = {
            "message":
            "The distribution's mean must be between -1000000 and 1000000",
            "res": False,
        }
        self.assertDictEqual(
            random_org.generateGaussians(
                api_key="peW",
                api_version="1",
                number=5,
                mean="0.0",
                standardDeviation="1.0",
                significantDigits="8",
            ),
            ret4,
        )

        ret5 = {
            "message": ("The distribution's standard deviation must be"
                        " between -1000000 and 1000000"),
            "res":
            False,
        }
        self.assertDictEqual(
            random_org.generateGaussians(
                api_key="peW",
                api_version="1",
                number=5,
                mean=0.0,
                standardDeviation="1.0",
                significantDigits="8",
            ),
            ret5,
        )

        ret6 = {
            "message":
            "The number of significant digits must be between 2 and 20",
            "res": False,
        }
        self.assertDictEqual(
            random_org.generateGaussians(
                api_key="peW",
                api_version="1",
                number=5,
                mean=0.0,
                standardDeviation=1.0,
                significantDigits="8",
            ),
            ret6,
        )

        ret7 = {"message": "Parameter 'apiKey' is malformed", "res": False}
        self.assertDictEqual(
            random_org.generateGaussians(
                api_key="peW",
                api_version="1",
                number=5,
                mean=0.0,
                standardDeviation=1.0,
                significantDigits=8,
            ),
            ret7,
        )