|
1 | 1 | 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 | +#= |
3 | 56 |
|
4 | 57 | @parameters t
|
5 | 58 |
|
|
374 | 427 |
|
375 | 428 | u0 = []
|
376 | 429 | prob = ODEProblem(sys, u0, (0, 1.5))
|
377 |
| - # sol = solve(prob, Rosenbrock23()) |
| 430 | + # sol = solve(prob, Rosenbrock23()) |
378 | 431 | end
|
| 432 | +
|
| 433 | +=# |
0 commit comments