def test_preset_index_with_all_presets_filled(self): p = PresetIndex() p.count = 64 p.indexes = [num for num in range(0, 64)] # Should have 64 presets self.assertEqual(64, p.number_of_presets) # And no free slots self.assertIsNone(p.first_empty_index_position)
def test_throws_exception_if_index_out_of_range(self): p = PresetIndex() p.count = 4 p.set_indexes([0, 1, 2, 3, 255]) self.assertEqual(p.number_of_presets, 4) self.assertFalse(p.is_valid_index(4)) self.assertFalse(p.is_valid_index(-1)) self.assertTrue(p.is_valid_index(0)) self.assertTrue(p.is_valid_index(1)) self.assertTrue(p.is_valid_index(3))
def test_adding_preset_modifies_both_index_and_preset(self): p = Preset() p.index = 123 pi = PresetIndex() pi.set_indexes([0, 1, 2, 3, 255]) pi.add_to_index(p) self.assertEqual(p.memory_slot, 4) self.assertEqual(pi.index_of_preset_with_memory_slot_number(4), 4) print "PI: {0}".format(pi.indexes)
def test_deleting_shuffles_indexes_left(self): p = PresetIndex() p.set_indexes([0, 1, 2, 3, 255]) self.assertEqual(4, p.number_of_presets) expected_index_list = list(p.indexes) del expected_index_list[0] expected_index_list.append(255) # logger.info("Is now: {0}".format(p.indexes)) p.delete_item_at_index(0) self.assertEqual(expected_index_list, p.indexes) self.assertEqual(3, p.number_of_presets)
def test_preset_index_can_provide_next_available_slot(self): p = PresetIndex() p.set_indexes([0, 1, 2, 3, 255]) self.assertEqual(4, p.next_available_memory_slot) p.set_indexes([0, 2, 8, 10, 255]) self.assertEqual(1, p.next_available_memory_slot) p.set_indexes([1, 2, 8, 10, 255]) self.assertEqual(0, p.next_available_memory_slot) p.set_indexes([1, 0, 2, 8, 10, 255]) self.assertEqual(3, p.next_available_memory_slot) # Fill it up entirely p.set_indexes(list(range(0, 64))) self.assertIsNone(p.next_available_memory_slot)
def test_preset_index_filling_gives_us_64_items(self): p = PresetIndex() p.set_indexes([0, 255]) self.assertEqual(1, p.number_of_presets) self.assertEqual(64, len(p.indexes))
def test_preset_indexes_are_swapped_ok(self): p = PresetIndex() p.count = 4 p.indexes = [0, 1, 2, 3, 255] p.swap(0, 3) self.assertEqual([3, 1, 2, 0, 255], p.indexes)
def post(self): json_dict = request.json preset_list = PresetIndex(json_dict) return evil_global.comms.save_full_preset_list(preset_list)