def test_circle_map_creation_custom_6_C_L(self): shape = Shape.objects.create(shape='C') line = Circle.objects.create(led_count=6, rotation='C', position='L') led_strip = LedStrip() # test correct map was made correct_map = [[0, 2, 0], [1, 0, 3], [6, 0, 4], [0, 5, 0]] self.assertEqual(led_strip.map, correct_map)
def test_circle_map_creation_default(self): shape = Shape.objects.create(shape='C') line = Circle.objects.create(led_count=4, rotation='C', position='T') led_strip = LedStrip() # test correct map was made correct_map = [[0, 1, 0], [4, 0, 2], [0, 3, 0]] self.assertEqual(led_strip.map, correct_map)
def test_circle_map_creation_custom_5_A_D(self): shape = Shape.objects.create(shape='C') line = Circle.objects.create(led_count=5, rotation='A', position='D') led_strip = LedStrip() # test correct map was made correct_map = [[0, 2, 0], [3, 0, 1], [4, 0, 5]] self.assertEqual(led_strip.map, correct_map)
def test_circle_map_creation_custom_7_A_R(self): shape = Shape.objects.create(shape='C') line = Circle.objects.create(led_count=7, rotation='A', position='R') led_strip = LedStrip() # test correct map was made correct_map = [[0, 0, 3, 0, 0], [0, 4, 0, 2, 0], [5, 0, 0, 0, 1], [0, 6, 0, 7, 0]] self.assertEqual(led_strip.map, correct_map)
def test_line_map_creation_custom_down(self): shape = Shape.objects.create(shape='L') line = Line.objects.create( led_count=4, direction='D', ) led_strip = LedStrip() # test correct map was made correct_map = [[1], [2], [3], [4]] self.assertEqual(led_strip.map, correct_map)
def test_line_map_creation_custom_right(self): shape = Shape.objects.create(shape='L') line = Line.objects.create( led_count=6, direction='R', ) led_strip = LedStrip() # test correct map was made correct_map = [[1, 2, 3, 4, 5, 6]] self.assertEqual(led_strip.map, correct_map)
def test_line_map_creation_custom_up(self): shape = Shape.objects.create(shape='L') line = Line.objects.create( led_count=18, direction='U', ) led_strip = LedStrip() # test correct map was made correct_map = [[18], [17], [16], [15], [14], [13], [12], [11], [10], [9], [8], [7], [6], [5], [4], [3], [2], [1]] self.assertEqual(led_strip.map, correct_map)
def test_line_map_creation_default(self): shape = Shape.objects.create(shape='L') line = Line.objects.create( led_count=1, direction='R', ) led_strip = LedStrip() # test correct map was made correct_map = [ [1], ] self.assertEqual(led_strip.map, correct_map)
def test_square_map_creation_default(self): shape = Shape.objects.create(shape='S') square = Square.objects.create( led_count=4, rotation='A', position='BL', height=1, width=1, ) led_strip = LedStrip() # test correct map was made correct_map = [ [0, 3, 0], [4, 0, 2], [0, 1, 0], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_TR_S_C(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=20, height=5, width=4, position='TR', direction='S', rotation='C') led_strip = LedStrip() # test correct map was made correct_map = [ [12, 13, 14, 1], [11, 20, 15, 2], [10, 19, 16, 3], [9, 18, 17, 4], [8, 7, 6, 5], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_TR_S_A(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=20, height=5, width=4, position='TR', direction='S', rotation='A') led_strip = LedStrip() # test correct map was made correct_map = [ [4, 3, 2, 1], [5, 16, 15, 14], [6, 17, 20, 13], [7, 18, 19, 12], [8, 9, 10, 11], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BL_S_A(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=15, height=5, width=3, position='BL', direction='S', rotation='A') led_strip = LedStrip() # test correct map was made correct_map = [ [9, 8, 7], [10, 15, 6], [11, 14, 5], [12, 13, 4], [1, 2, 3], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BL_H_even(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create( led_count=20, height=4, width=5, position='BL', direction='H', ) led_strip = LedStrip() # test correct map was made correct_map = [ [20, 19, 18, 17, 16], [11, 12, 13, 14, 15], [10, 9, 8, 7, 6], [1, 2, 3, 4, 5], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BR_H_even(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create( led_count=20, height=4, width=5, position='BR', direction='H', ) led_strip = LedStrip() # test correct map was made correct_map = [ [16, 17, 18, 19, 20], [15, 14, 13, 12, 11], [6, 7, 8, 9, 10], [5, 4, 3, 2, 1], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BL_V_odd(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create( led_count=20, height=4, width=5, position='BL', direction='V', ) led_strip = LedStrip() # test correct map was made correct_map = [ [4, 5, 12, 13, 20], [3, 6, 11, 14, 19], [2, 7, 10, 15, 18], [1, 8, 9, 16, 17], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BR_V_odd(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create( led_count=20, height=4, width=5, position='BR', direction='V', ) led_strip = LedStrip() # test correct map was made correct_map = [ [20, 13, 12, 5, 4], [19, 14, 11, 6, 3], [18, 15, 10, 7, 2], [17, 16, 9, 8, 1], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_TL_S_C(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=25, height=5, width=5, position='TL', direction='S', rotation='C') led_strip = LedStrip() # test correct map was made correct_map = [ [1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BL_S_C(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=15, height=5, width=3, position='BL', direction='S', rotation='C') led_strip = LedStrip() # test correct map was made correct_map = [ [5, 6, 7], [4, 15, 8], [3, 14, 9], [2, 13, 10], [1, 12, 11], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_TL_S_A(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=25, height=5, width=5, position='TL', direction='S', rotation='A') led_strip = LedStrip() # test correct map was made correct_map = [ [1, 16, 15, 14, 13], [2, 17, 24, 23, 12], [3, 18, 25, 22, 11], [4, 19, 20, 21, 10], [5, 6, 7, 8, 9], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BL_H_odd(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create( led_count=20, height=5, width=4, position='BL', direction='H', ) led_strip = LedStrip() # test correct map was made correct_map = [ [17, 18, 19, 20], [16, 15, 14, 13], [9, 10, 11, 12], [8, 7, 6, 5], [1, 2, 3, 4], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_TR_H_odd(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create( led_count=20, height=5, width=4, position='TR', direction='H', ) led_strip = LedStrip() # test correct map was made correct_map = [ [4, 3, 2, 1], [5, 6, 7, 8], [12, 11, 10, 9], [13, 14, 15, 16], [20, 19, 18, 17], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BR_S_C(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=42, height=7, width=6, position='BR', direction='S', rotation='C') led_strip = LedStrip() # test correct map was made correct_map = [ [12, 13, 14, 15, 16, 17], [11, 30, 31, 32, 33, 18], [10, 29, 40, 41, 34, 19], [9, 28, 39, 42, 35, 20], [8, 27, 38, 37, 36, 21], [7, 26, 25, 24, 23, 22], [6, 5, 4, 3, 2, 1], ] self.assertEqual(led_strip.map, correct_map)
def test_grid_map_creation_BR_S_A(self): shape = Shape.objects.create(shape='G') line = Grid.objects.create(led_count=42, height=7, width=6, position='BR', direction='S', rotation='A') led_strip = LedStrip() # test correct map was made correct_map = [ [12, 11, 10, 9, 8, 7], [13, 30, 29, 28, 27, 6], [14, 31, 40, 39, 26, 5], [15, 32, 41, 38, 25, 4], [16, 33, 42, 37, 24, 3], [17, 34, 35, 36, 23, 2], [18, 19, 20, 21, 22, 1], ] self.assertEqual(led_strip.map, correct_map)
def test_square_map_creation_custom(self): shape = Shape.objects.create(shape='S') square = Square.objects.create( led_count=22, rotation='C', position='BL', height=6, width=5, ) led_strip = LedStrip() # test correct map was made correct_map = [ [0, 7, 8, 9, 10, 11, 0], [6, 0, 0, 0, 0, 0, 12], [5, 0, 0, 0, 0, 0, 13], [4, 0, 0, 0, 0, 0, 14], [3, 0, 0, 0, 0, 0, 15], [2, 0, 0, 0, 0, 0, 16], [1, 0, 0, 0, 0, 0, 17], [0, 22, 21, 20, 19, 18, 0], ] self.assertEqual(led_strip.map, correct_map)
from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponseRedirect from django.shortcuts import render from django.urls import reverse from LEDApp.forms import DurationForm, CircleForm, GridForm, LineForm, ShapeForm, SquareForm from LEDApp.led_strip import LedStrip from LEDApp.models import Circle, Grid, Line, Shape, Square led_strip = LedStrip() def change_shape(request): """Clear shape database and load shape view""" try: s = Shape.objects.get(pk =1 ) s.delete() except: pass return HttpResponseRedirect(reverse('shape')) def circle_settings(request): """View function for circle settings form""" # Ensure that shape has been set to circle try: # try and retrieve shape shape = Shape.objects.get(pk = 1) # test if the shape is not set to circle