1+ const expect = require ( 'chai' ) . expect ;
2+ const drawLine = require ( './08-draw-line' ) ;
3+
4+ describe ( 'Bit Manipulation: drawLine' , function ( ) {
5+
6+ it ( '0' , function ( ) {
7+ const screen = [ 0x0 ] ;
8+ const width = 8 ;
9+ const x1 = 0 ;
10+ const x2 = 0 ;
11+ const y = 0 ;
12+
13+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
14+ 0b00000000
15+ ] ) ;
16+ } ) ;
17+
18+ it ( '1' , function ( ) {
19+ const screen = [ 0x0 ] ;
20+ const width = 8 ;
21+ const x1 = 0 ;
22+ const x2 = 1 ;
23+ const y = 0 ;
24+
25+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
26+ 0b10000000
27+ ] ) ;
28+ } ) ;
29+
30+ it ( '3' , function ( ) {
31+ const screen = [ 0x0 ] ;
32+ const width = 8 ;
33+ const x1 = 0 ;
34+ const x2 = 3 ;
35+ const y = 0 ;
36+
37+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
38+ 0b11100000
39+ ] ) ;
40+ } ) ;
41+
42+ it ( '7' , function ( ) {
43+ const screen = [ 0x0 ] ;
44+ const width = 8 ;
45+ const x1 = 0 ;
46+ const x2 = 7 ;
47+ const y = 0 ;
48+
49+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
50+ 0b11111110
51+ ] ) ;
52+ } ) ;
53+
54+ it ( '8 - all' , function ( ) {
55+ const screen = [ 0x0 ] ;
56+ const width = 8 ;
57+ const x1 = 0 ;
58+ const x2 = 8 ;
59+ const y = 0 ;
60+
61+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
62+ 0b11111111
63+ ] ) ;
64+ } ) ;
65+
66+ it ( '7-8' , function ( ) {
67+ const screen = [ 0x0 ] ;
68+ const width = 8 ;
69+ const x1 = 7 ;
70+ const x2 = 8 ;
71+ const y = 0 ;
72+
73+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
74+ 0b00000001
75+ ] ) ;
76+ } ) ;
77+
78+ it ( 'center' , function ( ) {
79+ const screen = [ 0x0 ] ;
80+ const width = 8 ;
81+ const x1 = 3 ;
82+ const x2 = 5 ;
83+ const y = 0 ;
84+
85+ expect ( drawLine ( screen , width , x1 , x2 , y ) [ 0 ] . toString ( 2 ) ) . to . equal ( '11000' ) ;
86+ } ) ;
87+
88+ it ( '6' , function ( ) {
89+ const screen = [ 0x0 ] ;
90+ const width = 8 ;
91+ const x1 = 6 ;
92+ const x2 = 8 ;
93+ const y = 0 ;
94+
95+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
96+ 0b00000011
97+ ] ) ;
98+ } ) ;
99+
100+ it ( '12 (5)' , function ( ) {
101+ const screen = [ 0x0 ] ;
102+ const width = 8 ;
103+ const x1 = 0 ;
104+ const x2 = 4 ;
105+ const y = 0 ;
106+
107+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
108+ 0b11110000
109+ ] ) ;
110+ } ) ;
111+
112+ it ( '2 bytes screen' , function ( ) {
113+ const screen = [ 0x0 , 0x0 ] ;
114+ const width = 16 ;
115+ const x1 = 6 ;
116+ const x2 = 12 ;
117+ const y = 0 ;
118+
119+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
120+ 0b00000011 , 0b11110000
121+ ] ) ;
122+ } ) ;
123+
124+ it ( '2x2 screen' , function ( ) {
125+ const screen = [ 0x0 , 0x0 ,
126+ 0x0 , 0x0 ] ;
127+ const width = 16 ;
128+ const x1 = 6 ;
129+ const x2 = 12 ;
130+ const y = 1 ;
131+
132+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
133+ 0b00000000 , 0b0000000 ,
134+ 0b00000011 , 0b11110000
135+ ] ) ;
136+ } ) ;
137+
138+ it ( '3x3 screen interbits' , function ( ) {
139+ const screen = [ 0x0 , 0x0 , 0x0 ,
140+ 0x0 , 0x0 , 0x0 ,
141+ 0x0 , 0x0 , 0x0 ] ;
142+ const width = 24 ;
143+ const x1 = 7 ;
144+ const x2 = 17 ;
145+ const y = 1 ;
146+
147+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
148+ 0b00000000 , 0b00000000 , 0b00000000 ,
149+ 0b00000001 , 0b11111111 , 0b10000000 ,
150+ 0b00000000 , 0b00000000 , 0b00000000
151+ ] ) ;
152+ } ) ;
153+
154+ xit ( '3x3 screen last byte high' , function ( ) {
155+ const screen = [ 0x0 , 0x0 , 0x0 ,
156+ 0x0 , 0x0 , 0x0 ,
157+ 0x0 , 0x0 , 0x0 ] ;
158+ const width = 24 ;
159+ const x1 = 16 ;
160+ const x2 = 17 ;
161+ const y = 2 ;
162+
163+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
164+ 0b00000000 , 0b00000000 , 0b00000000 ,
165+ 0b00000000 , 0b00000000 , 0b00000000 ,
166+ 0b00000000 , 0b00000000 , 0b10000000
167+ ] ) ;
168+ } ) ;
169+
170+ xit ( '3x3 screen last byte low' , function ( ) {
171+ const screen = [ 0x0 , 0x0 , 0x0 ,
172+ 0x0 , 0x0 , 0x0 ,
173+ 0x0 , 0x0 , 0x0 ] ;
174+ const width = 24 ;
175+ const x1 = 24 ;
176+ const x2 = 25 ;
177+ const y = 2 ;
178+
179+ expect ( drawLine ( screen , width , x1 , x2 , y ) ) . to . eql ( [
180+ 0b00000000 , 0b00000000 , 0b00000000 ,
181+ 0b00000000 , 0b00000000 , 0b00000000 ,
182+ 0b00000000 , 0b00000000 , 0b00000001
183+ ] ) ;
184+ } ) ;
185+ } ) ;
0 commit comments