@@ -2,13 +2,13 @@ using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq
2
2
using ModelingToolkitStandardLibrary. Electrical: _and, _or, _not, _xor
3
3
using ModelingToolkitStandardLibrary. Electrical: U, X, F0, F1, Z, W, L, H, DC
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
14
# Logic zeros and ones
@@ -33,18 +33,27 @@ using ModelingToolkitStandardLibrary.Electrical: convert_to_logic, get_logic_lev
33
33
@test X01. logic == [X, F0, F1]
34
34
@test X01Z. logic == [X, F0, F1, Z]
35
35
36
+ # Logic vector helpers
37
+ logic_vector = [U F0
38
+ F1 X]
39
+ size (logic_vector) == (2 , 2 )
40
+ axes (logic_vector) == (Base. OneTo (2 ), Base. OneTo (2 ))
41
+ getindex (logic_vector, 1 , 1 ) == U
42
+
36
43
# Logic helper functions
37
44
@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]
45
+ @test convert .(Logic, [1 , 0 , U]) == [F1, F0, U]
46
+ @test_throws " 3 isn't a valid `Logic` value" convert (Logic, 3 )
39
47
end
48
+
40
49
@testset " Logic tables and logic gate helpers" begin
41
50
# logic tables and logic gate helpers
42
51
@test size (AndTable) == size (OrTable) == size (XorTable) == (9 , 9 )
43
52
@test size (NotTable) == (9 ,)
44
53
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
54
+ @test _and (1 , 1 , U, W , 1 , 0 ) == F0
55
+ @test _or (0 , U , 1 , 1 ) == F1
56
+ @test _xor (0 , 1 , U, U , 1 , 1 ) == U
48
57
@test _not (1 ) == F0
49
58
50
59
A = [U, W, Z, F1, F0]
0 commit comments