def test_remove_tag__1_1_add_remove(self): tag_engine = TagEngine() tag_engine.storage['tag1'] = 2 ** 1 tag_engine.remove_tag('tag1') self.assertEqual(len(tag_engine.storage), 0)
def test_add_tag__return_m(self): tag_engine = TagEngine() tag_ids_expected = [1, 2, 4, 8, 16, 32] tag_ids_provided = tag_engine.add_tag( ['tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6']) self.assertEqual(tag_ids_expected, tag_ids_provided)
def test_remove_tag__0_1_add_remove(self): tag_engine = TagEngine() remove_result = tag_engine.remove_tag('tag1') self.assertEqual(remove_result, ['tag1']) self.assertEqual(len(tag_engine.gaps), 0) self.assertEqual(len(tag_engine.storage), 0)
def test_remove_tag__m_1_add_remove(self): tag_engine = TagEngine() test_range = 1000 for i in range(1, test_range): tag_engine.storage['tag' + str(i)] = 2 ** (i-1) tag_engine.remove_tag('tag1') self.assertEqual(tag_engine.gaps, [1])
def test_add_tag__high_amount_add(self): tag_engine = TagEngine() test_range = 10000 for i in range(1, test_range): tag_engine.add_tag('tag' + str(i)) for i in range(1, test_range): self.assertEqual(tag_engine.storage['tag' + str(i)], 2**(i - 1))
def test_add_tag__repeat_add(self): tag_engine = TagEngine() test_range = 100 for i in range(test_range): tag_engine.add_tag('tag') self.assertEqual(tag_engine.storage['tag'], 1) self.assertEqual(len(tag_engine.storage), 1) self.assertEqual(len(tag_engine.gaps), 0)
def test_get_tag_ids__m_get_from_empty(self): tag_engine = TagEngine() test_range = 1000 tags = [] for i in range(test_range): tags.append('tag' + str(i)) tag_id = tag_engine.get_tag_ids(tags) self.assertEqual(tag_id, [])
def test_add_tag__single_high_amount_add(self): tag_engine = TagEngine() test_range = 10000 tags_to_add = [] for i in range(1, test_range): tags_to_add.append('tag' + str(i)) tag_engine.add_tag(tags_to_add) for i in range(1, test_range): self.assertEqual(tag_engine.storage['tag' + str(i)], 2**(i - 1))
def test_get_tag_ids__m_get_wrong(self): tag_engine = TagEngine() test_range = 1000 tags = [] for i in range(test_range): tag_engine.storage['tag' + str(i)] = 2**(i - 1) for i in range(test_range, int(test_range / 2)): tag = 'tag' + str(i) tags.append(tag) tag_ids = tag_engine.get_tag_ids(tags) self.assertEqual(tag_ids, [])
def test_get_tag_ids__m_get(self): tag_engine = TagEngine() test_range = 30 tags = [] for i in range(test_range): tag = 'tag' + str(i) tags.append(tag) tag_engine.storage[tag] = 2**(i - 1) tag_ids = tag_engine.get_tag_ids(tags) for tag_id, i in zip(tag_ids, range(test_range)): self.assertEqual(tag_id, 2**(i - 1))
def test_get_tag_ids__partial_get_wrong(self): tag_engine = TagEngine() tag_engine.storage['tag1'] = 2**(1 - 1) tag_engine.storage['tag2'] = 2**(2 - 1) tag_engine.storage['tag3'] = 2**(3 - 1) tag_engine.storage['tag4'] = 2**(4 - 1) tag_engine.storage['tag5'] = 2**(5 - 1) tag_engine.storage['tag6'] = 2**(6 - 1) tags_requested = ['tag2', 'tag5', 'tag7', 'tag8', 'tag9'] tag_ids_expected = [2**(2 - 1), 2**(5 - 1)] tag_ids_output = tag_engine.get_tag_ids(tags_requested) self.assertEqual(tag_ids_expected, tag_ids_output)
def test_add_tag__m_1_add_remove(self): tag_engine = TagEngine() tag_engine.add_tag('tag1') tag_engine.add_tag('tag2') tag_engine.add_tag('tag3') tag_engine.add_tag('tag4') tag_engine.gaps.append(tag_engine.storage.pop('tag2')) tag_engine.add_tag('tag2') for i in range(1, 4): self.assertEqual(tag_engine.storage['tag' + str(i)], 2**(i - 1))
def test_add_tag__1_1_add_remove(self): tag_engine = TagEngine() tag_engine.add_tag('tag1') self.assertEqual(tag_engine.storage['tag1'], 2**0) tag_engine.storage.pop('tag1') tag_engine.add_tag('tag2') self.assertEqual(tag_engine.storage['tag2'], 2**0)
class UnitBase: def __init__(self): self.storage = pd.DataFrame(columns=COLUMN_NAMES) self.tagengine = TagEngine() def add_units(self, fields, tag=''): if tag == '': tag_id = DEFAULT_TAG_ID else: tag_id = self.tagengine.add_tag(tag) new_row = {COLUMN_NAMES[0]: fields, COLUMN_NAMES[1]: tag_id} self.storage = self.storage.append(new_row, ignore_index=True) unit_id = 0 return unit_id
# @brief Example Python program with Doxygen style comments. # # @section description_doxygen_example Description # Example Python program with Doxygen style comments. # # @section libraries_main Libraries/Modules # - time standard library (https://docs.python.org/3/library/time.html) # - Access to sleep function. # - sensors module (local) # - Access to Sensor and TempSensor classes. # # @section notes_doxygen_example Notes # - Comments are Doxygen compatible. # # @section todo_doxygen_example TODO # - None. # # @section author_doxygen_example Author(s) # - Created by John Woolsey on 05/27/2020. # - Modified by John Woolsey on 06/11/2020. # # Copyright (c) 2020 Woolsey Workshop. All rights reserved. import pandas as pd from tagengine import TagEngine if __name__ == "__main__": tag_engine = TagEngine('te1')
def test_remove_tag__m_m_add_remove(self): tag_engine = TagEngine() test_range = 1000 tag_engine.storage['tag1'] = 2 ** (1 - 1) tag_engine.storage['tag2'] = 2 ** (2 - 1) tag_engine.storage['tag3'] = 2 ** (3 - 1) tag_engine.storage['tag4'] = 2 ** (4 - 1) tag_engine.storage['tag5'] = 2 ** (5 - 1) tag_engine.storage['tag6'] = 2 ** (6 - 1) tag_engine.remove_tag('tag1') tag_engine.remove_tag('tag3') self.assertEqual(tag_engine.gaps, [1, 4]) tag_engine.gaps.pop() tag_engine.storage['tag3'] = 2 ** (3 - 1) tag_engine.gaps.pop() tag_engine.storage['tag1'] = 2 ** (1 - 1) for i in range(6): tag_engine.remove_tag('tag' + str(i+1)) self.assertEqual(len(tag_engine.gaps), 6) self.assertEqual(len(tag_engine.storage), 0)
def test_add_tag__return_1(self): tag_engine = TagEngine() tag_id_expected = 2**0 tag_id_provided = tag_engine.add_tag('tag1') self.assertEqual(tag_id_expected, tag_id_provided)
def __init__(self): self.storage = pd.DataFrame(columns=COLUMN_NAMES) self.tagengine = TagEngine()
def test_get_tag_ids__1_get(self): tag_engine = TagEngine() tag_engine.storage['tag1'] = 2**(1 - 1) tag_id = tag_engine.get_tag_ids('tag1') self.assertEqual(tag_id, 2**(1 - 1))
def test_get_tag_ids__1_get_from_empty(self): tag_engine = TagEngine() tag_id = tag_engine.get_tag_ids('tag1') self.assertEqual(tag_id, [])