1 /*
2  * Copyright (c) 2016 Helmut Neemann
3  * Use of this source code is governed by the GPL v3 license
4  * that can be found in the LICENSE file.
5  */
6 package de.neemann.digital.core.wiring;
7 
8 import de.neemann.digital.core.BurnException;
9 import de.neemann.digital.core.Model;
10 import de.neemann.digital.core.NodeException;
11 import de.neemann.digital.core.ObservableValue;
12 import de.neemann.digital.core.wiring.bus.DataBus;
13 import de.neemann.digital.draw.elements.PinException;
14 import junit.framework.TestCase;
15 
16 /**
17  */
18 public class DataBusTest extends TestCase {
19 
testSimple()20     public void testSimple() throws PinException, NodeException {
21         ObservableValue a = new ObservableValue("a", 4)
22                 .setToHighZ();
23         ObservableValue b = new ObservableValue("b", 4)
24                 .setToHighZ();
25 
26         Model m = new Model();
27 
28         ObservableValue out = new DataBus(null, m, a, b).getReadableOutput();
29 
30         a.setValue(1);
31         assertEquals(1, out.getValue());
32         a.setToHighZ();
33         b.setValue(2);
34         assertEquals(2, out.getValue());
35         b.setToHighZ();
36 
37 //        try {  ToDo HighZ
38 //            out.getValue();
39 //            assertTrue(false);
40 //        } catch (HighZException e) {
41 //            assertTrue(true);
42 //        }
43 
44         a.setValue(1);
45         b.setValue(1);
46         m.doStep();
47 
48         a.setValue(0);
49         b.setValue(0);
50         m.doStep();
51 
52         a.setValue(1);
53         b.setValue(0);
54         try {
55             m.doStep();
56             assertTrue(true);
57         } catch (BurnException e) {
58             assertTrue(true);
59         }
60 
61     }
62 
63 }
64