Skip to content

Commit

Permalink
Add 9 passing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
korenmiklos committed Aug 13, 2024
1 parent 23f1cb0 commit d2cea8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Targets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 15 additions & 36 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d2cea8c

Please sign in to comment.