From d2cea8c1926610e2b1ffda9e936065c3d8646150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Koren?= Date: Tue, 13 Aug 2024 14:47:53 +0200 Subject: [PATCH] Add 9 passing unit tests --- src/Targets.jl | 2 +- test/runtests.jl | 51 ++++++++++++++---------------------------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/Targets.jl b/src/Targets.jl index 33cd8a3..4c43eb5 100644 --- a/src/Targets.jl +++ b/src/Targets.jl @@ -99,7 +99,7 @@ macro target(expr) if @capture(value, func_(args__)) quote - Core.eval(Variables, :($($(QuoteNode(name))) = $(Target($(QuoteNode(func)), [$(QuoteNode.(args)...)])))) + Core.eval(Variables, :($($(QuoteNode(name))) = $(Target($(QuoteNode(func)), Symbol[$(QuoteNode.(args)...)])))) end else quote diff --git a/test/runtests.jl b/test/runtests.jl index 79b321d..0b687a6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,69 +1,48 @@ using Test using Targets +add(x, y) = x + y +add1(x) = x + 1 +mult(x, y) = x * y + @testset "Targets" begin @testset "Basic functionality" begin @target a = 1 @target b = 2 - @test get_value(a) == 1 - @test get_value(b) == 2 + @test (@get a) == 1 + @test (@get b) == 2 - add(x, y) = x + y @target c = add(a, b) - @test get_value(c) == 3 + @test (@get c) == 3 end @testset "Updating values" begin @target x = 5 - @target y = x + 1 - @test get_value(y) == 6 + @target y = add1(x) + @test (@get y) == 6 @target x = 10 - @test get_value(y) == 11 + @test (@get y) == 11 end @testset "Function modification" begin - mult(x, y) = x * y @target m = 3 @target n = 4 @target p = mult(m, n) - @test get_value(p) == 12 + @test (@get p) == 12 # Modify the function - mult(x, y) = x * y + 1 - @test get_value(p) == 13 - end - - @testset "Complex dependencies" begin - @target base = 2 - @target exp = 3 - pow(x, y) = x^y - @target result = pow(base, exp) - @test get_value(result) == 8 - - @target base = 3 - @test get_value(result) == 27 - end - - @testset "Reset functionality" begin - @target to_reset = 42 - @test get_value(to_reset) == 42 - - reset_targets!() - @test_throws UndefVarError get_value(to_reset) - end - - @testset "Error handling" begin - @test_throws ErrorException @target error_case = nonexistent_function(1, 2) + Main.mult(x, y) = x * y + 1 + @test (@get p) == 13 end @testset "Built-in function handling" begin @target a = 5 @target b = 7 @target sum_ab = +(a, b) - @test get_value(sum_ab) == 12 + @test (@get sum_ab) == 12 @target a = 10 - @test get_value(sum_ab) == 17 + @test (@get sum_ab) == 17 end end \ No newline at end of file