@@ -5,18 +5,18 @@ import {V, Vector} from "Vector";
5
5
6
6
import { GetHelpers } from "test/helpers/Helpers" ;
7
7
8
- import { CreateBusAction } from "digital/actions/addition/BusActionFactory" ;
8
+ import { CreateBusAction , GetComponentBusPorts } from "digital/actions/addition/BusActionFactory" ;
9
9
10
10
import { DigitalCircuitDesigner , InputPort , OutputPort } from "digital/models" ;
11
11
12
- import { ANDGate , BCDDisplay , ConstantNumber , IC , ICData , LED , Multiplexer , Switch } from "digital/models/ioobjects" ;
12
+ import { ANDGate , BCDDisplay , BUFGate , ConstantNumber , IC ,
13
+ ICData , LED , Multiplexer , Switch } from "digital/models/ioobjects" ;
13
14
14
15
15
16
describe ( "Bus Action" , ( ) => {
16
17
const designer = new DigitalCircuitDesigner ( 0 ) ;
17
18
const { Place } = GetHelpers ( designer ) ;
18
19
19
-
20
20
function expectBusConnections ( outs : OutputPort [ ] , ins : InputPort [ ] ) {
21
21
// Helper functions to for expected connectivity
22
22
const expectAllDisconnected = ( ) => {
@@ -285,4 +285,88 @@ describe("Bus Action", () => {
285
285
expect ( i3 . getConnections ( ) [ 0 ] ) . toBe ( ic . getConnections ( ) [ 3 ] ) ;
286
286
expect ( i4 . getConnections ( ) [ 0 ] ) . toBe ( ic . getConnections ( ) [ 1 ] ) ;
287
287
} ) ;
288
+ test ( "Switches at exact same position" , ( ) => {
289
+ const [ i1 , i2 , i3 , i4 , bcd1 ] = Place ( new Switch ( ) , new Switch ( ) , new Switch ( ) ,
290
+ new Switch ( ) , new BCDDisplay ( ) ) ;
291
+
292
+ i1 . setPos ( V ( 0 , 0 ) ) ;
293
+ i2 . setPos ( V ( 0 , 0 ) ) ;
294
+ i3 . setPos ( V ( 0 , 0 ) ) ;
295
+ i4 . setPos ( V ( 0 , 0 ) ) ;
296
+ bcd1 . setPos ( V ( 200 , 0 ) ) ;
297
+
298
+ // Expect every single switch to connect, but we can't assert anything about the order of connections
299
+ expectBusConnections ( [ i1 , i2 , i3 , i4 ] . flatMap ( ( i ) => i . getOutputPorts ( ) ) , bcd1 . getInputPorts ( ) ) ;
300
+ } ) ;
301
+
302
+ describe ( "Bus Components" , ( ) => {
303
+ // Buses that should work
304
+ test ( "Constant Number -> BCD Display" , ( ) => {
305
+ const [ c1 , bcd1 ] = Place ( new ConstantNumber ( ) , new BCDDisplay ( ) ) ;
306
+
307
+ const [ iports , oports ] = GetComponentBusPorts ( [ c1 , bcd1 ] ) ;
308
+
309
+ expect ( iports ) . toHaveLength ( 4 ) ;
310
+ expect ( oports ) . toHaveLength ( 4 ) ;
311
+
312
+ expectBusConnections ( oports , iports ) ;
313
+ } ) ;
314
+ test ( "4 Switches -> BCD Display" , ( ) => {
315
+ const [ i1 , i2 , i3 , i4 , bcd1 ] = Place ( new Switch ( ) , new Switch ( ) , new Switch ( ) ,
316
+ new Switch ( ) , new BCDDisplay ( ) ) ;
317
+
318
+ const [ iports , oports ] = GetComponentBusPorts ( [ i1 , i2 , bcd1 , i3 , i4 ] ) ;
319
+
320
+ expect ( iports ) . toHaveLength ( 4 ) ;
321
+ expect ( oports ) . toHaveLength ( 4 ) ;
322
+
323
+ expectBusConnections ( oports , iports ) ;
324
+ } ) ;
325
+ test ( "4 Switches -> 2 ANDGates" , ( ) => {
326
+ const [ i1 , i2 , i3 , i4 , a1 , a2 ] = Place ( new Switch ( ) , new Switch ( ) , new Switch ( ) ,
327
+ new Switch ( ) , new ANDGate ( ) , new ANDGate ( ) ) ;
328
+
329
+ const [ iports , oports ] = GetComponentBusPorts ( [ i1 , a2 , i3 , i2 , i4 , a1 ] ) ;
330
+
331
+ expect ( iports ) . toHaveLength ( 4 ) ;
332
+ expect ( oports ) . toHaveLength ( 4 ) ;
333
+
334
+ expectBusConnections ( oports , iports ) ;
335
+ } ) ;
336
+ test ( "6 Switches -> Mux" , ( ) => {
337
+ const [ i1 , i2 , i3 , i4 , i5 , i6 , m1 ] = Place ( new Switch ( ) , new Switch ( ) , new Switch ( ) , new Switch ( ) ,
338
+ new Switch ( ) , new Switch ( ) , new Multiplexer ( ) ) ;
339
+
340
+ const [ iports , oports ] = GetComponentBusPorts ( [ i1 , i2 , i3 , i4 , i5 , i6 , m1 ] ) ;
341
+
342
+ expect ( iports ) . toHaveLength ( 6 ) ;
343
+ expect ( oports ) . toHaveLength ( 6 ) ;
344
+
345
+ expectBusConnections ( oports , iports ) ;
346
+ } ) ;
347
+
348
+ // Buses that should not work
349
+ test ( "Fail: BUFGate -> BUFGate" , ( ) => {
350
+ const [ b1 , b2 ] = Place ( new BUFGate ( ) , new BUFGate ( ) ) ;
351
+
352
+ const [ iports , oports ] = GetComponentBusPorts ( [ b1 , b2 ] ) ;
353
+
354
+ expect ( iports ) . not . toHaveLength ( oports . length ) ;
355
+ } ) ;
356
+ test ( "Fail: 3 Switches -> BCD Display" , ( ) => {
357
+ const [ i1 , i2 , i3 , bcd1 ] = Place ( new Switch ( ) , new Switch ( ) , new Switch ( ) , new BCDDisplay ( ) ) ;
358
+
359
+ const [ iports , oports ] = GetComponentBusPorts ( [ i1 , i2 , i3 , bcd1 ] ) ;
360
+
361
+ expect ( iports ) . not . toHaveLength ( oports . length ) ;
362
+ } ) ;
363
+ test ( "Fail: 7 Switches -> Mux" , ( ) => {
364
+ const [ i1 , i2 , i3 , i4 , i5 , i6 , i7 , m1 ] = Place ( new Switch ( ) , new Switch ( ) , new Switch ( ) , new Switch ( ) ,
365
+ new Switch ( ) , new Switch ( ) , new Switch ( ) , new Multiplexer ( ) ) ;
366
+
367
+ const [ iports , oports ] = GetComponentBusPorts ( [ i1 , i2 , i3 , i4 , i5 , i6 , i7 , m1 ] ) ;
368
+
369
+ expect ( iports ) . not . toHaveLength ( oports . length ) ;
370
+ } ) ;
371
+ } ) ;
288
372
} ) ;
0 commit comments