Skip to content

Commit ad2587f

Browse files
committed
test: increase the test coverage
1 parent 1469804 commit ad2587f

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

test/Electrical/digital.jl

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq, Test
22
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
44
using ModelingToolkitStandardLibrary.Electrical: AndTable, OrTable, NotTable, XorTable
5-
using ModelingToolkitStandardLibrary.Electrical: convert_to_logic, get_logic_level
5+
using ModelingToolkitStandardLibrary.Electrical: get_logic_level
66
# using ModelingToolkitStandardLibrary.Electrical: Set, Reset
77

88
@testset "Logic, logic-vectors and helpers" begin
99
# Logic and helper functions
1010
@test length(instances(Logic)) == 9
11-
@test convert_to_logic.([1, 0]) |> typeof == Vector{Logic}
11+
@test convert.(Logic, [1, 0]) |> typeof == Vector{Logic}
1212
@test get_logic_level(Z) == 5
1313

14+
io = IOBuffer()
15+
show(io, MIME("text/plain"), Uninitialized)
16+
@test String(take!(io)) == "U"
17+
1418
# Logic zeros and ones
1519
@test zero(Logic) == zero(U) == F0
1620
@test one(Logic) == one(U) == F1
@@ -33,18 +37,35 @@ using ModelingToolkitStandardLibrary.Electrical: convert_to_logic, get_logic_lev
3337
@test X01.logic == [X, F0, F1]
3438
@test X01Z.logic == [X, F0, F1, Z]
3539

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+
3649
# Logic helper functions
3750
@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)
3953
end
54+
4055
@testset "Logic tables and logic gate helpers" begin
4156
# logic tables and logic gate helpers
4257
@test size(AndTable) == size(OrTable) == size(XorTable) == (9, 9)
4358
@test size(NotTable) == (9,)
4459

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)
4869
@test _not(1) == F0
4970

5071
A = [U, W, Z, F1, F0]

0 commit comments

Comments
 (0)