1
1
using ModelingToolkitStandardLibrary. Electrical, ModelingToolkit, OrdinaryDiffEq, Test
2
2
using ModelingToolkitStandardLibrary. Electrical: _and, _or, _not, _xor
3
- using ModelingToolkitStandardLibrary. Electrical: U, X, F0, F1, Z, W, L, H, DC
3
+ using ModelingToolkitStandardLibrary. Electrical: U, X, F0, F1, Z, W, L, H, DC, Uninitialized
4
4
using ModelingToolkitStandardLibrary. Electrical: AndTable, OrTable, NotTable, XorTable
5
- using ModelingToolkitStandardLibrary. Electrical: convert_to_logic, get_logic_level
5
+ using ModelingToolkitStandardLibrary. Electrical: get_logic_level
6
6
# using ModelingToolkitStandardLibrary.Electrical: Set, Reset
7
7
8
8
@testset " Logic, logic-vectors and helpers" begin
9
9
# Logic and helper functions
10
10
@test length (instances (Logic)) == 9
11
- @test convert_to_logic .( [1 , 0 ]) |> typeof == Vector{Logic}
11
+ @test convert .(Logic, [1 , 0 ]) |> typeof == Vector{Logic}
12
12
@test get_logic_level (Z) == 5
13
13
14
+ io = IOBuffer ()
15
+ show (io, MIME (" text/plain" ), Uninitialized)
16
+ @test String (take! (io)) == " U"
17
+
14
18
# Logic zeros and ones
15
19
@test zero (Logic) == zero (U) == F0
16
20
@test one (Logic) == one (U) == F1
@@ -33,18 +37,35 @@ using ModelingToolkitStandardLibrary.Electrical: convert_to_logic, get_logic_lev
33
37
@test X01. logic == [X, F0, F1]
34
38
@test X01Z. logic == [X, F0, F1, Z]
35
39
40
+ # Logic vector helpers
41
+ logic_vector = StdULogicVector ([U F0
42
+ F1 X])
43
+ size (logic_vector) == (2 , 2 )
44
+ axes (logic_vector) == (Base. OneTo (2 ), Base. OneTo (2 ))
45
+ getindex (logic_vector, 1 , 1 ) == U
46
+
47
+ getindex (StdLogicVector ([U, F0, F1, X]), 1 ) == U
48
+
36
49
# Logic helper functions
37
50
@test get_logic_level .([U, X, F0, F1, Z, W, L, H, DC]) == 1 : 9
38
- @test convert_to_logic .([1 , 0 , U]) == [F1, F0, U]
51
+ @test convert .(Logic, [1 , 0 , U]) == [F1, F0, U]
52
+ @test_throws " 3 isn't a valid `Logic` value" convert (Logic, 3 )
39
53
end
54
+
40
55
@testset " Logic tables and logic gate helpers" begin
41
56
# logic tables and logic gate helpers
42
57
@test size (AndTable) == size (OrTable) == size (XorTable) == (9 , 9 )
43
58
@test size (NotTable) == (9 ,)
44
59
45
- @test _and (1 , 1 , 1 , 1 , 1 , 0 ) == F0
46
- @test _or (0 , 1 , 1 , 1 ) == F1
47
- @test _xor (0 , 1 , 1 , 1 , 1 , 1 ) == F1
60
+ # tests (Number, Number), (Logic, Logic), (Logic, Number) inputs
61
+ @test _and (1 , 1 , U, W, 1 , 0 ) == F0
62
+ @test _or (0 , 1 , U, 1 ) == F1
63
+ @test _xor (0 , 1 , U, U, 1 , 1 ) == U
64
+ # tests (Number, Logic) input
65
+ @info _and (1 , F1) == F1
66
+ @info _or (0 , F0) == F0
67
+ @test _xor (1 , F0) == F1
68
+ # tests Number and Logic (via internal convert)
48
69
@test _not (1 ) == F0
49
70
50
71
A = [U, W, Z, F1, F0]
0 commit comments