def test_flame_class(self):
   """Tests for the lab_hardware.Flame class."""
   
   # Initialize constants
   map_radius = 1.0
   good_points = [[2.0, 2.0],
                  [1.0001, 0.0],
                  [100, 200],
                  [0.0, 1.0001],
                  [-1.0001, 0.0],
                  [0.0, -1.0001],
                  [-2.0, -2.0],
                  [2.0, 0, 0.1, -0.1]]
   bad_points = [[1.0, 0.0],
                 [0.0, 1.0],
                 [0.0, 0.0],
                 [0.5, 0.5],
                 [-1.0, 0.0],
                 [0.0, -1.0],
                 [-0.5, -0.5],
                 [0.1, 0.5, -0.5, 0.1]]
   
   # Initialize flame object
   test_flame = lab_hardware.Flame(lambda p: sim_functions.one_sphere(p, map_radius))
   
   # Test the initialization
   self.assertIsInstance(test_flame, lab_hardware.Flame,
                         "Test flame object not initialized to Flame class.")
   self.assertFalse(test_flame.get_state(),
                    "Flame state not initialized to False")
   
   # Test the flame ignites when given a valid operating point
   for point in good_points:
     self.assertEqual(test_flame.update(point), True,
                      "Flame not returning correct state from update method (True).")
     self.assertTrue(test_flame.get_state(),
                     "Flame does not ignite when moved to good op. point.")
   
   # Test the flame blows out when given a bad operating point
   for point in bad_points:
     self.assertEqual(test_flame.update(point), False,
                      "Flame not returning correct state from update method (False).")
     self.assertFalse(test_flame.get_state(),
                      "Flame does not blow out when moved to a bad op. point.")
예제 #2
0
 def __init__(self, p_atm, t_step, t_step_ctrl, sensor_list, mfc_list,
              control_law_list):
   '''
   Constructor. Adds components of the combustor to its component list, sets
   the atmospheric pressure, and gets everything ready to go (theoretically).
   
   Args:
     p_atm (float): atmospheric pressure in psi
     t_step (float): time step for system simulation
     sensor_list (list, Instrument): list of sensor objects
     mfc_list (list, MFC): list of MFC objects
     control_law_list (list, function): list of control law functions
   '''
   
   # Initialize constants
   self.p_atm = p_atm
   self.t_step = t_step
   self.time = 0.0  # initialize current time to zero
   self.flame = Flame(operating_map=lambda p: sim_functions.one_sphere(p, radius=2.0))
   self.controller = Controller(mfc_list, control_law_list, t_step_ctrl)
예제 #3
0
    def test_flame_class(self):
        """Tests for the lab_hardware.Flame class."""

        # Initialize constants
        map_radius = 1.0
        good_points = [[2.0, 2.0], [1.0001, 0.0], [100, 200], [0.0, 1.0001],
                       [-1.0001, 0.0], [0.0, -1.0001], [-2.0, -2.0],
                       [2.0, 0, 0.1, -0.1]]
        bad_points = [[1.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.5, 0.5],
                      [-1.0, 0.0], [0.0, -1.0], [-0.5, -0.5],
                      [0.1, 0.5, -0.5, 0.1]]

        # Initialize flame object
        test_flame = lab_hardware.Flame(
            lambda p: sim_functions.one_sphere(p, map_radius))

        # Test the initialization
        self.assertIsInstance(
            test_flame, lab_hardware.Flame,
            "Test flame object not initialized to Flame class.")
        self.assertFalse(test_flame.get_state(),
                         "Flame state not initialized to False")

        # Test the flame ignites when given a valid operating point
        for point in good_points:
            self.assertEqual(
                test_flame.update(point), True,
                "Flame not returning correct state from update method (True).")
            self.assertTrue(
                test_flame.get_state(),
                "Flame does not ignite when moved to good op. point.")

        # Test the flame blows out when given a bad operating point
        for point in bad_points:
            self.assertEqual(
                test_flame.update(point), False,
                "Flame not returning correct state from update method (False)."
            )
            self.assertFalse(
                test_flame.get_state(),
                "Flame does not blow out when moved to a bad op. point.")
 def test_one_sphere(self):
   """Tests for one_sphere function."""
   
   # Define constants
   radii = [1.0, 2.0, 3, 4, 100]
   bad_radii = [0, 0.0, -1, -2, -0]
   origin_list = [0, 0.0, [0, 0], [0, 0.0], [0, 0, 0, 0, 0, 0, 0]]
   default_bad = [1, 1.0, [1, 0], [0, 1], [0, 0, 1], [0.5, 0.5, 0.1, -0.1]]
   default_good = [1.1, 2, -1.1, [2, 0], [-1, 1], [-1, 0.5, 0.5, 0.1]]
   assigned_good = [100.1, [100, 1], [-100, 0.1], [100, -1, 1, 0]]
   
   # Test the default function implementation
   for origin in origin_list:
     self.assertFalse(sim_functions.one_sphere(origin),
                      "Default one_sphere misclassifies origin.")
   for point in default_bad:
     self.assertFalse(sim_functions.one_sphere(point),
                      "Default one_sphere misclassifies points inside sphere.")
   for point in default_good:
     self.assertTrue(sim_functions.one_sphere(point),
                     "Default one_sphere misclassifies points outside sphere.")
   
   # Test ValueError raised when radius = 0
   with self.assertRaises(ValueError):
     for radius in bad_radii:
       sim_functions.one_sphere(0, radius)
   
   # Test that string arguments raise a TypeError
   with self.assertRaises(TypeError):
     sim_functions.one_sphere("0.0")
     sim_functions.one_sphere(["0", "0"])
     sim_functions.one_sphere(0, radius="1")
     sim_functions.one_sphere([0, 0], radius="1")
     sim_functions.one_sphere(0, radius=[1, 1])
     sim_functions.one_sphere([0, 0], radius=[1, 1])
     
   # Test some different radii
   for radius in radii:
     for point in default_bad:
       self.assertFalse(sim_functions.one_sphere(point, radius),
                        "Misclassifying bad points when assigning radius.")
     for point in assigned_good:
       self.assertTrue(sim_functions.one_sphere(point, radius),
                       "Misclassifying good points when assigning radius.")