<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy
import unittest

from rmgpy.chem.constants import *

################################################################################

class ConstantsTest(unittest.TestCase):
    """
    Contains unit tests for the rmgpy.chem.constants module.
    """
    
    def testQuantity(self):
        """
        Unit tests for the Quantity class.
        """

        q = Quantity(10.0)
        self.assertEqual(q.value, 10.0)
        self.assertEqual(q.uncertainty, 0.0)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "")
        self.assertEqual(q.uncertaintyType, "")

        q = Quantity((10.0,"cm"))
        self.assertEqual(q.value, 0.1)
        self.assertEqual(q.uncertainty, 0.0)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "")

        q = Quantity((10.0,"cm","+|-",2.0))
        self.assertEqual(q.value, 0.1)
        self.assertEqual(q.uncertainty, 0.02)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "+|-")
        
        q = Quantity((10.0,"cm","*|/",2.0))
        self.assertEqual(q.value, 0.1)
        self.assertEqual(q.uncertainty, 2.0)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "*|/")
        
        q = Quantity(([30.0,20.0,10.0],"cm","+|-",2.0))
        self.assertEqual(q.value, 0.0)
        self.assertEqual(q.uncertainty, 0.02)
        self.assertEqual(q.values[0], 0.3)
        self.assertEqual(q.values[1], 0.2)
        self.assertEqual(q.values[2], 0.1)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "+|-")
        
        q = Quantity(([10.0,20.0,30.0],"cm","+|-",[1.0,2.0,3.0]))
        self.assertEqual(q.value, 0.0)
        self.assertEqual(q.uncertainty, 0.0)
        self.assertEqual(q.values[0], 0.1)
        self.assertEqual(q.values[1], 0.2)
        self.assertEqual(q.values[2], 0.3)
        self.assertEqual(q.uncertainties[0], 0.01)
        self.assertEqual(q.uncertainties[1], 0.02)
        self.assertEqual(q.uncertainties[2], 0.03)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "+|-")
        
################################################################################

if __name__ == '__main__':
    unittest.main( testRunner = unittest.TextTestRunner(verbosity=2) )<commit_msg>Added unit tests for the new constants object.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy
import unittest

from rmgpy.chem.constants import *

################################################################################

class ConstantsTest(unittest.TestCase):
    """
    Contains unit tests for the rmgpy.chem.constants module.
    """
    
    def testQuantity(self):
        """
        Unit tests for the Quantity class.
        """

        q = Quantity(10.0)
        self.assertEqual(q.value, 10.0)
        self.assertEqual(q.uncertainty, 0.0)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "")
        self.assertEqual(q.uncertaintyType, "")

        q = Quantity((10.0,"cm"))
        self.assertEqual(q.value, 0.1)
        self.assertEqual(q.uncertainty, 0.0)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "")

        q = Quantity((10.0,"cm","+|-",2.0))
        self.assertEqual(q.value, 0.1)
        self.assertEqual(q.uncertainty, 0.02)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "+|-")
        
        q = Quantity((10.0,"cm","*|/",2.0))
        self.assertEqual(q.value, 0.1)
        self.assertEqual(q.uncertainty, 2.0)
        self.assertEqual(q.values, None)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "*|/")
        
        q = Quantity(([30.0,20.0,10.0],"cm","+|-",2.0))
        self.assertEqual(q.value, 0.0)
        self.assertEqual(q.uncertainty, 0.02)
        self.assertEqual(q.values[0], 0.3)
        self.assertEqual(q.values[1], 0.2)
        self.assertEqual(q.values[2], 0.1)
        self.assertEqual(q.uncertainties, None)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "+|-")
        
        q = Quantity(([10.0,20.0,30.0],"cm","+|-",[1.0,2.0,3.0]))
        self.assertEqual(q.value, 0.0)
        self.assertEqual(q.uncertainty, 0.0)
        self.assertEqual(q.values[0], 0.1)
        self.assertEqual(q.values[1], 0.2)
        self.assertEqual(q.values[2], 0.3)
        self.assertEqual(q.uncertainties[0], 0.01)
        self.assertEqual(q.uncertainties[1], 0.02)
        self.assertEqual(q.uncertainties[2], 0.03)
        self.assertEqual(q.units, "cm")
        self.assertEqual(q.uncertaintyType, "+|-")
        
################################################################################

class TestConstants(unittest.TestCase):
    """
    Contains unit tests of the Constants class. These tests ensure that the
    values of the constants are correct (or at least that they do not change!)
    """
    
    def testAvogadroConstant(self):
        self.assertAlmostEqual(constants.Na / pq.constants.N_A.simplified, 1.0, 6)

    def testBoltzmannConstant(self):
        self.assertAlmostEqual(constants.kB / pq.constants.Boltzmann_constant.simplified, 1.0, 6)
    
    def testGasLawConstant(self):
        self.assertAlmostEqual(constants.R / pq.constants.R.simplified, 1.0, 6)
    
    def testPlanckConstant(self):
        self.assertAlmostEqual(constants.h / pq.constants.Planck_constant.simplified, 1.0, 6)
    
    def testSpeedOfLight(self):
        self.assertAlmostEqual(constants.c / 299792458, 1.0, 6)
    
    def testPi(self):
        self.assertAlmostEqual(constants.pi / math.pi, 1.0, 6)

################################################################################

if __name__ == '__main__':
    unittest.main(testRunner=unittest.TextTestRunner(verbosity=2))
{'fraction_non_alphanumeric': 0.20811875189336565, 'fraction_numerical': 0.034686458648894275, 'mean_word_length': 2.72, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2326938', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2127, 'n_words': 315}