def test_RPN_convert(self):
     t = RPN_converter().convert([5, Operator(np.multiply,1), "(",1,Operator(np.add,0),2,")"])
     self.assertEqual(t[0], 5)
     self.assertEqual(t[1], 1)
     self.assertEqual(t[2], 2)
     self.assertTrue(isinstance(t[3], Operator))
     self.assertTrue(isinstance(t[4], Operator))
Example #2
0
 def test_add_operator_age_wrong(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("First name is required", actual.messages)
Example #3
0
 def test_add_operator_birth_wrong(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("Date of birth is required", actual.messages)
Example #4
0
 def test_add_operator_drone_license(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("Drone license is required", actual.messages)
Example #5
0
    def test_fail_license(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertFalse(act.is_valid())
Example #6
0
    def test_fail_dob(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.drone_license = 1
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertFalse(act.is_valid())
Example #7
0
    def test_allocate_success(self):
        # Arrange
        dr = Drone("Test drone", class_type=1)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertTrue(act.is_valid())
    def test_commit(self):
        #Arrange
        op = Operator()
        op.first_name = "monty"
        op.family_name = "python"
        op.date_of_birth = date(1990, 9, 30)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 5
        opStore = OperatorStore()

        action = opStore.add(op)

        #Act
        if action.is_valid():
            action.commit()
        else:
            for i in action.messages:
                print(i)

        #Assert
        listy = []
        for i in opStore.list_all():
            listy.append(opStore.get(i))
        self.assertIn(op, listy)
    def test_has_rescue_endorsement(self):
        # Arrange
        dr = Drone("Test drone", rescue=True)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertFalse(act.is_valid())
        self.assertIn("Operator does not have rescue endorsement", act.messages)
    def test_holds_correct_license(self):
        # Arrange
        dr = Drone("Test drone", class_type=2)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertFalse(act.is_valid())
        self.assertIn("Operator does not have correct drone license", act.messages)
Example #11
0
    def test_only_one_drone(self):
        # Arrange
        dr = Drone("Test drone", class_type=1)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        op.drone = Drone("Yet another")
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)
        # Assert
        self.assertFalse(act.is_valid())
        self.assertIn("Operator can only control one drone", act.messages)
Example #12
0
    def test_has_rescue_endorsement_success(self):
        # Arrange
        dr = Drone("Test drone", rescue=True)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        op.rescue_endorsement = True
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertTrue(act.is_valid())
Example #13
0
    def test_commit(self):
        # Arrange
        dr = Drone("Test drone", class_type=1)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)
        act.commit()

        # Assert
        self.assertEquals(dr.operator, op)
        self.assertEquals(op.drone, dr)
Example #14
0
    def __init__(self):
        self.functions = {
            'EXP': Function(np.exp),
            'LOG': Function(np.log),
            'SIN': Function(np.sin),
            'COS': Function(np.cos),
            'SQRT': Function(np.sqrt)
        }

        self.operators = {
            'PLUSS': Operator(np.add, 0),
            'GANGE': Operator(np.multiply, 1),
            'DELE': Operator(np.divide, 1),
            'MINUS': Operator(np.subtract, 0)
        }
Example #15
0
    def add_operator(self):
        """ Starts a new drone and displays it in the list. """
        # Start a new drone instance

        operator = Operator()
        # Display the drone
        self.view_operator(operator, self._save_new_operator)
Example #16
0
 def allocate(self, drone, fname, lname):
     """ Starts the allocation of a drone to an operator. """
     fname = fname.strip("'")
     lname = lname.strip("'")
     cursor = self._conn.cursor()
     query = 'SELECT ID, FirstName, LastName, DroneLicense, RescueEndorsement FROM Operator WHERE FirstName = %s AND LastName = %s'
     cursor.execute(query, (fname, lname))
     for (id, fname, lname, license, rescue) in cursor:
         operator = Operator(id, fname, lname, license, rescue)
         try:
             query = 'UPDATE Drone SET OperatorID = %s WHERE ID = %s'
             cursor.execute(query, (operator.id, drone.id))
         except:
             query = 'SELECT Operator.FirstName, Operator.LastName FROM Operator LEFT OUTER JOIN Drone ON Operator.ID = Drone.OperatorID WHERE Operator.ID = Drone.OperatorID AND Drone.ID = %s'
             cursor.execute(query, (drone.id, ))
             for (fname, lname) in cursor:
                 print(
                     "Validation errors :\n- drone already allocated to " +
                     str(fname) + " " + str(lname))
                 overwrite = raw_input(
                     "Do you want to continue [ Y / n ]? ")
                 if overwrite == 'Y' or 'y':
                     query = 'UPDATE Drone SET OperatorID = NULL WHERE ID = %s'
                     cursor.execute(query, (drone.id, ))
                     query = 'UPDATE Drone SET OperatorID = %s WHERE ID = %s'
                     cursor.execute(query, (operator.id, drone.id))
         #query = 'UPDATE Drone SET OperatorID = %s FROM Drone LEFT OUTER JOIN Operator ON Drone.OperatorID = Operator.ID WHERE Drone.ID = %s'
         #cursor.execute(query, (operator.id, int(drone.id)))
         #query = 'UPDATE Operator SET DroneID = %s FROM Operator INNER JOIN Drone ON Operator.ID = Drone.OperatorID WHERE Operator.ID = %s'
         #cursor.execute(query, (drone.id, operator.id))
     '''action = DroneAction(drone, operator, self._allocate)
Example #17
0
    def build_eval_ops(
        self,
        wavefunction: wavefunctions.Wavefunction,
        operator: operators.Operator,
        hparams: tf.contrib.training.HParams,
        shared_resources: Dict[graph_builders.ResourceName, Any],
    ) -> EvalOps:
        """Adds wavefunction evaluation ops to the graph.

    Args:
      wavefunction: Wavefunction ansatz to evalutate.
      operator: Operator corresponding to the value we want to evaluate.
      hparams: Hyperparameters of the evaluation procedure.
      shared_resources: System resources shared among different modules.

    Returns:
      NamedTuple holding tensors needed to run evaluation.
    """
        batch_size = hparams.batch_size
        n_sites = hparams.num_sites

        configs = graph_builders.get_configs(shared_resources, batch_size,
                                             n_sites)
        mc_step, acc_rate = graph_builders.get_monte_carlo_sampling(
            shared_resources, configs, wavefunction)

        value = tf.reduce_mean(operator.local_value(wavefunction, configs))
        eval_ops = EvalOps(
            value=value,
            mc_step=mc_step,
            acceptance_rate=acc_rate,
            placeholder_input=None,
            wavefunction_value=None,
        )
        return eval_ops
Example #18
0
    def add_operator(self):
        """ Starts a new drone and displays it in the list. """
        # Start a new drone instance
        'TODO: Start a new drone'
        last_id = self.operators.get_max()
        fname = 'Operator'
        lname = str(last_id)
        operator = Operator(last_id + 1, fname, lname, 1, 0)

        # Display the drone
        self.view_operator(operator, self._save_new_operator)
Example #19
0
 def load(cmd):
     """
     :param cmd. Example: 'abc:+1' means queue abc add one worker. 'abc:=1 means queue abc have one worker'
     """
     try:
         pattern = r'(.*)%s(%s)(\d*)' % (WorkerInstruction.SEPERATOR, '|'.join(map(lambda x: re.escape(x.slug), Operator.ALL)))
         queue, operator_slug, worker_cnt = re.findall(pattern, cmd)[0]
         operator = Operator.get(operator_slug)
         worker_cnt = int(worker_cnt)
     except:
         raise InstructionCMDException(cmd)
     return queue, operator, worker_cnt
Example #20
0
 def add_operator(self):
     """ Starts a new operator and displays it in the list. """
     # Start a new operator instance
     print('FINISH: Start a new operator')
     operator = Operator()
     operator.first_name = ""
     operator.family_name = ""
     operator.drone_license = 1
     operator.rescue_endorsement = 1
     operator.operations = 0
     # Display the operator
     self.view_operator(operator, self._save_new_operator)
Example #21
0
 def load(cmd):
     """
     :param cmd. Example: 'abc:+1' means queue abc add one worker. 'abc:=1 means queue abc have one worker'
     """
     try:
         pattern = r'(.*)%s(%s)(\d*)' % (
             WorkerInstruction.SEPERATOR, '|'.join(
                 map(lambda x: re.escape(x.slug), Operator.ALL)))
         queue, operator_slug, worker_cnt = re.findall(pattern, cmd)[0]
         operator = Operator.get(operator_slug)
         worker_cnt = int(worker_cnt)
     except:
         raise InstructionCMDException(cmd)
     return queue, operator, worker_cnt
Example #22
0
    def test_pass_all(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 5
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertTrue(act.is_valid())
Example #23
0
    def edit_operator(self, event):
        # Retrieve the identifer of the drone
        item = self.tree.item(self.tree.focus())

        operator = Operator()
        name = item['values'][0].split()
        operator.first_name = name[0]
        operator.last_name = name[1]
        operator.drone_license = item['values'][1]
        operator.rescue_endorsement = item['values'][2]
        operator.number_of_operations = item['values'][3]
        #,item['values'][1], item['values'][2], item['values'][3]

        # Display the drone
        self.view_operator(operator, self._update_operator)
Example #24
0
 def test_add_operator_pass_all_rules(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertTrue(len(actual.messages) == 0)
Example #25
0
    def test_add(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 5
        store = OperatorStore()

        # Act
        act = store.add(op)
        act.commit()

        # Assert
        self.assertEqual(store.get(1), op)
Example #26
0
 def test_operatorStore_added_successfully(self):
     #Arrange
     op = Operator()
     op.first_name = "Afzal"
     op.family_name = "Rahim"
     dob = date(1974, 9, 12)
     op.date_of_birth = dob
     op.drone_license = 2
     op.rescue_endorsement = True
     op.operations = 6
     store = OperatorStore()
     
     #Act
     act = store.add(op)
     
     if act.is_valid():
         act.commit()
     #Assert
     #self.assertTrue(store.get(op.id), True, "Operator has not been added successfully")
     self.assertTrue(store.get(op.id))
Example #27
0
 def test_add_operator_rescue_5(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 2
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("More than 5 rescue operations is required",
                   actual.messages)
Example #28
0
 def test_operator_validation(self):
     #Arrange
     op = Operator()
     op.first_name = "Afzal"
     op.family_name = "Rahim"
     dob = date(1974, 9, 12)
     op.date_of_birth = dob
     op.drone_license = 2
     op.rescue_endorsement = True
     op.operations = 6
     store = OperatorStore()
     
     #Act
     act = store.add(op)
     
     #Assert
     if act.is_valid():
         act.commit()
     #print(act.messages)
     #print(store._operators)    
     self.assertTrue(act.is_valid())
Example #29
0
 def test_add_operator_successfully(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     if actual.is_valid():
         actual.commit()
     self.assertIn(operator.id, operatorstore._operators)
Example #30
0
 def test_add_operator_age_more_than_20(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(2000, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn(
         "Operator should be at least twenty to hold a class 2 license",
         actual.messages)
Example #31
0
    def test_fail_endorsement(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        op.drone_license = 1
        op.rescue_endorsement = True
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertFalse(act.is_valid())
 def test_2_should_Sub(self):
     operator = Operator(2)
     self.assertEqual('-' , operator.toString())
 def test_3_should_Mul(self):
     operator = Operator(3)
     self.assertEqual('*' , operator.toString())
 def test_1_should_Plus(self):
     operator = Operator(1)
     self.assertEqual('+' , operator.toString())