Skip to content

Commit 3305aa9

Browse files
committed
test: digital logic and gate helpers
1 parent 8473fef commit 3305aa9

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

test/Electrical/digital.jl

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
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: AndTable, OrTable, NotTable, XorTable
5+
using ModelingToolkitStandardLibrary.Electrical: convert_to_logic, get_logic_level
6+
# using ModelingToolkitStandardLibrary.Electrical: Set, Reset
7+
8+
@testset "Logic, logic-vectors and helpers" begin
9+
# Logic and helper functions
10+
@test length(instances(Logic)) == 9
11+
@test convert_to_logic.([1, 0]) |> typeof == Vector{Logic}
12+
@test get_logic_level(Z) == 5
13+
14+
# Logic zeros and ones
15+
@test zero(Logic) == zero(U) == F0
16+
@test one(Logic) == one(U) == F1
17+
@test ones(Logic, 2, 2) == [F1 F1
18+
F1 F1]
19+
20+
# Logic vectors
21+
u_logic = StdULogicVector([U, W, X, 1])
22+
@test typeof(u_logic.logic) == Vector{Logic}
23+
@test get_logic_level(u_logic) == [1, 6, 2, 4]
24+
25+
logic = StdLogicVector([U, W, X, 1])
26+
@test typeof(logic.logic) == Vector{Logic}
27+
@test get_logic_level(logic) == [1, 6, 2, 4]
28+
29+
# Predefiend logic vectors
30+
@test std_ulogic.logic == [U, X, F0, F1, Z, W, L, H, DC]
31+
@test UX01.logic == [U, X, F0, F1]
32+
@test UX01Z.logic == [U, X, F0, F1, Z]
33+
@test X01.logic == [X, F0, F1]
34+
@test X01Z.logic == [X, F0, F1, Z]
35+
36+
# Logic helper functions
37+
@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]
39+
end
40+
@testset "Logic tables and logic gate helpers" begin
41+
# logic tables and logic gate helpers
42+
@test size(AndTable) == size(OrTable) == size(XorTable) == (9, 9)
43+
@test size(NotTable) == (9,)
44+
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
48+
@test _not(1) == F0
49+
50+
A = [U, W, Z, F1, F0]
51+
B = [U, W, X, F0, DC]
52+
_xor.(A, B) == _and.(_or.(A, _not.(B)), _or.(_not.(A), B))
53+
end
54+
55+
#=
356
457
@parameters t
558
@@ -374,5 +427,7 @@ end
374427
375428
u0 = []
376429
prob = ODEProblem(sys, u0, (0, 1.5))
377-
# sol = solve(prob, Rosenbrock23())
430+
# sol = solve(prob, Rosenbrock23())
378431
end
432+
433+
=#

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)