Пример #1
0
    def test_stack(self):

        #check stack_object is of class Stack
        self.assertIsInstance(stacks.Stack(), stacks.Stack)

        #check Stacks attribute items is of class list
        self.assertIsInstance(stacks.Stack().items, list)
Пример #2
0
    def test_is_balanced(self):

        #check is_balanced function works
        self.assertEqual(stacks.is_balanced(stacks.Stack(), '{()}'), True)
        self.assertEqual(stacks.is_balanced(stacks.Stack(), '{()'), False)

        #checks that an error is raised when expected
        with self.assertRaises(ValueError):

            stacks.is_balanced(stacks.is_balanced(stacks.Stack(), '{{f'))
Пример #3
0
 def testStackMax(self):
     stack = stacks.Stack([5, 8, 3, 12, 2])
     self.assertEqual(stack.max(), 12)
     stack.pop()
     stack.pop()
     self.assertEqual(stack.max(), 8)
     stack.push(15)
     self.assertEqual(stack.max(), 15)
     stack = stacks.Stack()
     self.assertEqual(stack.max(), None)
Пример #4
0
def match_symb(symb_str):
    symb_pairs = {'(': ')', '[': ']', '{': '}', '<': '>'}

    openers = symb_pairs.keys()
    my_stack = stacks.Stack()

    index = 0

    while index < len(symb_str):
        symb = symb_str[index]

        if symb in openers:
            my_stack.push(symb)

        else:
            if my_stack.is_empty():
                return False

            else:
                top_item = my_stack.pop()
                if symb != symb_pairs[top_item]:
                    return False
        index += 1

    if my_stack.is_empty():
        return True
Пример #5
0
    def test_stack_operation(self):

        my_stack = stacks.Stack()
        my_stack.push(1)

        #check methods all work
        self.assertEqual(my_stack.items[0], 1)
        self.assertEqual(my_stack.peek(), 1)
        self.assertEqual(my_stack.size(), 1)
        self.assertEqual(my_stack.is_empty(), False)
        self.assertEqual(my_stack.pop(), 1)
Пример #6
0
    def test_efi(self):
        import pylab as pl
        n_sio = 1.434
        n_ta = 2.05

        stacks_n = np.array([1.0, n_sio, n_ta, n_sio, n_ta, n_sio,
                             1.5163])  # matches "GLASS" in TFcalc
        stacks_d = np.array([270.22, 189.02, 270.22, 189.02, 270.22])
        stack = stacks.Stack(stacks_n, stacks_d)

        rs, rp = stack.reflectivity(1550)
        print("Reflectivity: {:.2f}%".format(rs * 100))
        x, y = stack.efi(1550, 30)
        pl.plot(x, y, '-')
        pl.show()
Пример #7
0
def main():
    # OBJECT CREATION OF CLASSES
    functions_class_object = functions.Functions(parameter)
    stack_class_object = stacks.Stack(parameter)
    tags_class_object = tags.Tags(parameter)

    # INITIAL BUCKET CREATION FOR YAML FILE UPLOADING
    try:
        s3.create_bucket(Bucket=parameter["InitBucketName"],
                         CreateBucketConfiguration={
                             'LocationConstraint': parameter["BucketConfig"]
                         })
    except ClientError:
        print("Data Bucket Already Created")

    # UPLOADING OF YAML FILE OBJECT
    functions_class_object.upload_object()

    # STACK CREATION , UPDATION OR DELETION AS PER REQUIREMENT
    stack_class_object.stack_handler()

    # UPLOADING OF OBJECTS USING FOLDER
    functions_class_object.upload_objects()

    # Tag Creation
    tagset1 = tags.make_tags({'notdivby2': '2no', 'key1': 'val1'})
    #print(tagset1)
    tagset2 = tags.make_tags({'divby2': '2yes', 'key1': 'val1'})
    #print(tagset1)
    # Tag Insertion
    tracker = 1
    while tracker != 11:
        if tracker % 2 == 0:
            obj_name = '{}.txt'.format(tracker)
            tags_class_object.tagging_insertion(obj_name, tagset2)
            print("yo")
        else:
            obj_name = '{}.txt'.format(tracker)
            tags_class_object.tagging_insertion(obj_name, tagset1)
            print("no")
        tracker = tracker + 1
Пример #8
0
    def test_reflectivity(self):
        """
        Simulate HR@1064nm, HT@808nm stack, check reflectivity at 1064nm

        From:
        http://www.rp-photonics.com/coating_demo_dichroic.html
        """
        n_sio = 1.434
        n_ta = 2.299

        stacks_n = np.array([1.0, n_sio] + [n_ta, n_sio] * 8)
        stacks_n[-1] = 1.52
        stacks_d = np.array([
            364, 114, 181, 113, 181, 113, 178, 112, 178, 115, 178, 111, 173,
            108, 196, 129
        ])
        stack = stacks.Stack(stacks_n, stacks_d)

        rs, rp = stack.reflectivity(1064)

        self.assertAlmostEqual(rs, 0.9982097, 6)
        self.assertAlmostEqual(rp, 0.9982097, 6)
Пример #9
0
 def setUp(self):
     self.stack = stacks.Stack([1.0, 1.0, 1.0, 1.0], [0.25, 0.25], 45.0)
Пример #10
0
 def testStackPush(self):
     stack = stacks.Stack([5, 8, 3, 12, 2])
     self.assertEqual(stack.to_list(), [5, 8, 3, 12, 2])
     stack.push(4)
     self.assertEqual(stack.to_list(), [5, 8, 3, 12, 2, 4])
Пример #11
0
 def testStackPop(self):
     stack = stacks.Stack([5, 8, 3, 12, 2])
     self.assertEqual(stack.pop(), 2)
     self.assertEqual(stack.to_list(), [5, 8, 3, 12])
     stack = stacks.Stack()
     self.assertEqual(stack.peek(), None)