
samples = int(1e6)

minimum = 1.
maximum = 17.
center = 7.
stddev = 5.


## VARIABLES FROM RANDOM TRUNCATED NORMAL DISTRIBUTION

from lib.rtnorm import rtnorm

variables = rtnorm(minimum, maximum, mu=center, sigma=stddev, size=samples)


## PLOT THEIR HISTOGRAM

import matplotlib.pyplot as plot

plot.hist(variables, bins=400)
plot.show()



import unittest
import matplotlib.pyplot as plot
import numpy as np

import sys
sys.path.append('.')  # T_T

from lib.rtnorm import rtnorm


class RunTest(unittest.TestCase):

    longMessage = True

    def test_histogram(self):
        """
        This should plot a histogram looking like a gaussian
        ... It does.
        """
        # CONFIGURATION (play with different values)
        samples = int(1e6)
        minimum = 1.
        maximum = 17.
        center = 7.
        stddev = 5.

        # VARIABLES FROM RANDOM TRUNCATED NORMAL DISTRIBUTION
        variables = rtnorm(minimum, maximum, mu=center, sigma=stddev,
                           size=samples)

        # PLOT THEIR HISTOGRAM
        plot.hist(variables, bins=400)
        plot.show()

    def test_sanity(self):
        """
        Simple sanity test for the random truncated normal distribution.
        """
        from sys import maxint

        # Generate an array with one number
        r = rtnorm(0, maxint)

        self.assertTrue(isinstance(r, np.ndarray))
        self.assertTrue(len(r) == 1)
        self.assertTrue((r > 0).all())
        self.assertTrue((r < maxint).all())

        # Generate an array with 42 numbers
        r = rtnorm(0, maxint, size=42)

        self.assertTrue(isinstance(r, np.ndarray))
        self.assertTrue(len(r) == 42)
        self.assertTrue((r > 0).all())
        self.assertTrue((r < maxint).all())

Fix the random truncated distribution tests
Fix the random truncated distribution tests

  
- samples = int(1e6)
+ import unittest
+ import matplotlib.pyplot as plot
+ import numpy as np
  
+ import sys
+ sys.path.append('.')  # T_T
- minimum = 1.
- maximum = 17.
- center = 7.
- stddev = 5.
- 
- 
- ## VARIABLES FROM RANDOM TRUNCATED NORMAL DISTRIBUTION
  
  from lib.rtnorm import rtnorm
  
- variables = rtnorm(minimum, maximum, mu=center, sigma=stddev, size=samples)
  
+ class RunTest(unittest.TestCase):
  
- ## PLOT THEIR HISTOGRAM
+     longMessage = True
  
- import matplotlib.pyplot as plot
+     def test_histogram(self):
+         """
+         This should plot a histogram looking like a gaussian
+         ... It does.
+         """
+         # CONFIGURATION (play with different values)
+         samples = int(1e6)
+         minimum = 1.
+         maximum = 17.
+         center = 7.
+         stddev = 5.
  
- plot.hist(variables, bins=400)
- plot.show()
+         # VARIABLES FROM RANDOM TRUNCATED NORMAL DISTRIBUTION
+         variables = rtnorm(minimum, maximum, mu=center, sigma=stddev,
+                            size=samples)
  
+         # PLOT THEIR HISTOGRAM
+         plot.hist(variables, bins=400)
+         plot.show()
  
+     def test_sanity(self):
+         """
+         Simple sanity test for the random truncated normal distribution.
+         """
+         from sys import maxint
+ 
+         # Generate an array with one number
+         r = rtnorm(0, maxint)
+ 
+         self.assertTrue(isinstance(r, np.ndarray))
+         self.assertTrue(len(r) == 1)
+         self.assertTrue((r > 0).all())
+         self.assertTrue((r < maxint).all())
+ 
+         # Generate an array with 42 numbers
+         r = rtnorm(0, maxint, size=42)
+ 
+         self.assertTrue(isinstance(r, np.ndarray))
+         self.assertTrue(len(r) == 42)
+         self.assertTrue((r > 0).all())
+         self.assertTrue((r < maxint).all())
+ 
Fix the random truncated distribution tests
## Code Before:

samples = int(1e6)

minimum = 1.
maximum = 17.
center = 7.
stddev = 5.


## VARIABLES FROM RANDOM TRUNCATED NORMAL DISTRIBUTION

from lib.rtnorm import rtnorm

variables = rtnorm(minimum, maximum, mu=center, sigma=stddev, size=samples)


## PLOT THEIR HISTOGRAM

import matplotlib.pyplot as plot

plot.hist(variables, bins=400)
plot.show()


## Instruction:
Fix the random truncated distribution tests
## Code After:

import unittest
import matplotlib.pyplot as plot
import numpy as np

import sys
sys.path.append('.')  # T_T

from lib.rtnorm import rtnorm


class RunTest(unittest.TestCase):

    longMessage = True

    def test_histogram(self):
        """
        This should plot a histogram looking like a gaussian
        ... It does.
        """
        # CONFIGURATION (play with different values)
        samples = int(1e6)
        minimum = 1.
        maximum = 17.
        center = 7.
        stddev = 5.

        # VARIABLES FROM RANDOM TRUNCATED NORMAL DISTRIBUTION
        variables = rtnorm(minimum, maximum, mu=center, sigma=stddev,
                           size=samples)

        # PLOT THEIR HISTOGRAM
        plot.hist(variables, bins=400)
        plot.show()

    def test_sanity(self):
        """
        Simple sanity test for the random truncated normal distribution.
        """
        from sys import maxint

        # Generate an array with one number
        r = rtnorm(0, maxint)

        self.assertTrue(isinstance(r, np.ndarray))
        self.assertTrue(len(r) == 1)
        self.assertTrue((r > 0).all())
        self.assertTrue((r < maxint).all())

        # Generate an array with 42 numbers
        r = rtnorm(0, maxint, size=42)

        self.assertTrue(isinstance(r, np.ndarray))
        self.assertTrue(len(r) == 42)
        self.assertTrue((r > 0).all())
        self.assertTrue((r < maxint).all())
