Skip to content

Commit 2c6ee42

Browse files
committed
test: digital logic and gate helpers
1 parent 8473fef commit 2c6ee42

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

test/Electrical/digital.jl

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq, Test
2-
using ModelingToolkitStandardLibrary.Electrical: Set, Reset, _and, _or, _not
2+
using ModelingToolkitStandardLibrary.Electrical: _and, _or, _not, _xor
3+
using ModelingToolkitStandardLibrary.Electrical: U, X, F0, F1, Z, W, L, H, DC
4+
using ModelingToolkitStandardLibrary.Electrical: convert_to_logic, get_logic_level
5+
# using ModelingToolkitStandardLibrary.Electrical: Set, Reset
6+
7+
# Logic and helper functions
8+
@test length(instances(Logic)) == 9
9+
@test convert_to_logic.([1, 0]) |> typeof == Vector{Logic}
10+
@test get_logic_level(Z) == 5
11+
12+
# Logic zeros and ones
13+
@test zero(Logic) == zero(U) == F0
14+
@test one(Logic) == one(U) == F1
15+
@test ones(Logic, 2, 2) == [F1 F1
16+
F1 F1]
17+
18+
# Logic vectors
19+
u_logic = StdULogicVector([U, W, X, 1])
20+
@test typeof(u_logic.logic) == Vector{Logic}
21+
@test get_logic_level(u_logic) == [1, 6, 2, 4]
22+
23+
logic = StdLogicVector([U, W, X, 1])
24+
@test typeof(logic.logic) == Vector{Logic}
25+
@test get_logic_level(logic) == [1, 6, 2, 4]
26+
27+
# Predefiend logic vectors
28+
@test std_ulogic.logic == [U, X, F0, F1, Z, W, L, H, DC]
29+
@test UX01.logic == [U, X, F0, F1]
30+
@test UX01Z.logic == [U, X, F0, F1, Z]
31+
@test X01.logic == [X, F0, F1]
32+
@test X01Z.logic == [X, F0, F1, Z]
33+
34+
# logic tables and logic gate helpers
35+
@test AndTable[1, 1] = U
36+
@test OrTable[1, 1] = U
37+
@test NotTable[1, 1] = U
38+
@test XorTable[1, 1] = U
39+
@test size(AndTable) == size(OrTable) == size(NotTable) == size(XorTable) == (9, 9)
40+
41+
@test _and(1, 1, 1, 1, 1, 1) == F1
42+
@test _or(0, 1, 1, 1, 1, 1) == F0
43+
@test _xor(0, 1, 1, 1, 1, 1) == F1
44+
@test _not(1) == F0
45+
46+
# Logic helper functions
47+
@test get_logic_level.([U, X, F0, F1, Z, W, L, H, DC]) == 1:9
48+
@test convert_to_logic.([1, 0, U]) == [F1, F0, U]
49+
50+
#=
351
452
@parameters t
553
@@ -374,5 +422,7 @@ end
374422
375423
u0 = []
376424
prob = ODEProblem(sys, u0, (0, 1.5))
377-
# sol = solve(prob, Rosenbrock23())
425+
# sol = solve(prob, Rosenbrock23())
378426
end
427+
428+
=#

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using SafeTestsets
99

1010
# Electrical
1111
@safetestset "Analog Circuits" begin include("Electrical/analog.jl") end
12-
#@safetestset "Digital Circuits" begin include("Electrical/digital.jl") end
12+
@safetestset "Digital Circuits" begin include("Electrical/digital.jl") end
1313
@safetestset "RC Circuit Demo" begin include("demo.jl") end
1414
@safetestset "Chua Circuit Demo" begin include("chua_circuit.jl") end
1515

0 commit comments

Comments
 (0)