Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Sep 27, 2024
1 parent 9160318 commit f659ed0
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 30 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![codecov](https://codecov.io/gh/Kyjor/JulGame.jl/graph/badge.svg?token=535VSQ21MJ)](https://codecov.io/gh/Kyjor/JulGame.jl)
[Documentation is in progress!](https://docs.kyjor.io/JulGame.jl)

[Documentation](https://docs.kyjor.io/JulGame.jl)

[Trello board](https://trello.com/b/M6uH0Jmy/julgame)
![JulGame Logo](https://github.com/Kyjor/JulGame.jl/assets/13784123/f68ece3a-62a1-48fb-a905-c7c8b9aa35c1)
Expand Down Expand Up @@ -103,7 +104,7 @@ This is a list of references that I used in order to get JulGame where it is, al
- and so many others who I will note some of in the future :)

## Games Made With JulGame
Here I will be keeping a list for the first games created with JulGame by external contributors (aka not me). If you would like to see games that I have made, check them out at https://kyjor.itch.io
Here I will be keeping a list for the first **original** games created with JulGame by external contributors (aka not me). If you would like to see games that I have made, check them out at https://kyjor.itch.io

1.
2.
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Component/Animator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

function Component.update(this::InternalAnimator, currentRenderTime, deltaTime)
if this.currentAnimation.animatedFPS < 1 || (this.playOnce && this.lastFrame == length(this.currentAnimation.frames))
if this.currentAnimation.animatedFPS < 1 || (this.playOnce && this.lastFrame == length(this.currentAnimation.frames)) || this.sprite == C_NULL || this.sprite === nothing
return
end
deltaTime = (currentRenderTime - this.lastUpdate) / 1000.0
Expand Down
80 changes: 53 additions & 27 deletions test/math/lerptests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,69 @@
num = 0
num2 = 1

@testset "Lerp test halfway" begin
@test Math.Lerp(num, num2, 0.5) == 0.5
end
@testset "Lerp tests" begin
@testset "Lerp test halfway" begin
@test Math.Lerp(num, num2, 0.5) == 0.5
end

@testset "Lerp test negative" begin
@test Math.Lerp(num, num2, -1) == 0
end
@testset "Lerp test negative" begin
@test Math.Lerp(num, num2, -1) == 0
end

@testset "Lerp test over 1" begin
@test Math.Lerp(num, num2, 2) == 1
end
@testset "Lerp test over 1" begin
@test Math.Lerp(num, num2, 2) == 1
end

@testset "Lerp test 0" begin
@test Math.Lerp(num, num2, 0) == 0
end
@testset "Lerp test 0" begin
@test Math.Lerp(num, num2, 0) == 0
end

@testset "Lerp test 1" begin
@test Math.Lerp(num, num2, 1) == 1
@testset "Lerp test 1" begin
@test Math.Lerp(num, num2, 1) == 1
end
end

@testset "SmoothLerp test halfway" begin
@test Math.SmoothLerp(num, num2, 0.5) == 0.49999999999999994
end
@testset "SmoothLerp tests" begin
@testset "SmoothLerp test halfway" begin
@test Math.SmoothLerp(num, num2, 0.5) == 0.49999999999999994
end

@testset "SmoothLerp test negative" begin
@test Math.SmoothLerp(num, num2, -1) == 0
end
@testset "SmoothLerp test negative" begin
@test Math.SmoothLerp(num, num2, -1) == 0
end

@testset "SmoothLerp test over 1" begin
@test Math.SmoothLerp(num, num2, 2) == 1
end
@testset "SmoothLerp test over 1" begin
@test Math.SmoothLerp(num, num2, 2) == 1
end

@testset "SmoothLerp test 0" begin
@test Math.SmoothLerp(num, num2, 0) == 0
end

@testset "SmoothLerp test 0" begin
@test Math.SmoothLerp(num, num2, 0) == 0
@testset "SmoothLerp test 1" begin
@test Math.SmoothLerp(num, num2, 1) == 1
end
end

@testset "overflow_lerp tests" begin
@testset "overflow_lerp test halfway" begin
@test Math.overflow_lerp(num, num2, 0.5) == 0.5
end

@testset "overflow_lerp test negative" begin
@test Math.overflow_lerp(num, num2, -1) == -1
end

@testset "overflow_lerp test over 1" begin
@test Math.overflow_lerp(num, num2, 2) == 2
end

@testset "overflow_lerp test 0" begin
@test Math.overflow_lerp(num, num2, 0) == 0
end

@testset "SmoothLerp test 1" begin
@test Math.SmoothLerp(num, num2, 1) == 1
@testset "overflow_lerp test 1" begin
@test Math.overflow_lerp(num, num2, 1) == 1
end
end
end
5 changes: 5 additions & 0 deletions test/math/mathtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ using JulGame
@testset "Math tests" begin
include("lerptests.jl")
include("vectortests.jl")

@testset "Math tests" begin
@test Math.normalize(Math.Vector2f(1, 1)) == Math.Vector2f(0.7071067811865475, 0.7071067811865475)
@test Math.distance(Math.Vector2f(0, 0), Math.Vector2f(3, 4)) == 5.0
end
end
215 changes: 215 additions & 0 deletions test/math/vectortests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,219 @@
@test v.z == -2
end
end

@testset "Vector3f tests " begin
@testset "Vector3f constructors" begin
@test Math.Vector3f(1.0, 2.0, 3.0).x == 1.0
@test Math.Vector3f(1.0, 2.0, 3.0).y == 2.0
@test Math.Vector3f(1.0, 2.0, 3.0).z == 3.0

@test Math.Vector3f(1, 2, 3).x == 1.0
@test Math.Vector3f(1, 2, 3).y == 2.0
@test Math.Vector3f(1, 2, 3).z == 3.0

@test Math.Vector3f(1.5, 2, 3).x == 1.5
@test Math.Vector3f(1.5, 2, 3).y == 2.0
@test Math.Vector3f(1.5, 2, 3).z == 3.0
@test Math.Vector3f(1, 2.5, 3).x == 1.0
@test Math.Vector3f(1, 2.5, 3).y == 2.5
@test Math.Vector3f(1, 2.5, 3).z == 3.0
@test Math.Vector3f(1, 2, 3.5).x == 1.0
@test Math.Vector3f(1, 2, 3.5).y == 2.0
@test Math.Vector3f(1, 2, 3.5).z == 3.5
end

@testset "Vector3f addition" begin
vec1 = Math.Vector3f(1.0, 2.0, 3.0)
vec2 = Math.Vector3f(4.0, 5.0, 6.0)
@test vec1 + vec2 == Math.Vector3f(5.0, 7.0, 9.0)
@test vec1 + 2 == Math.Vector3f(3.0, 4.0, 5.0)
@test vec1 + 2.0 == Math.Vector3f(3.0, 4.0, 5.0)
@test 2 + vec1 == Math.Vector3f(3.0, 4.0, 5.0)
@test 2.0 + vec1 == Math.Vector3f(3.0, 4.0, 5.0)
end

@testset "Vector3f subtraction" begin
vec1 = Math.Vector3f(3.0, 4.0, 5.0)
vec2 = Math.Vector3f(1.0, 2.0, 3.0)
@test vec1 - vec2 == Math.Vector3f(2.0, 2.0, 2.0)
@test vec1 - 2 == Math.Vector3f(1.0, 2.0, 3.0)
@test vec1 - 2.0 == Math.Vector3f(1.0, 2.0, 3.0)
@test 2 - vec1 == Math.Vector3f(-1.0, -2.0, -3.0)
@test 2.0 - vec1 == Math.Vector3f(-1.0, -2.0, -3.0)
end

@testset "Vector3f multiplication" begin
vec1 = Math.Vector3f(2.0, 3.0, 4.0)
vec2 = Math.Vector3f(4.0, 5.0, 6.0)
int = 2
float = 1.5

@testset "Vector3f and Vector3f multiplication" begin
@test vec1 * vec2 == Math.Vector3f(8.0, 15.0, 24.0)
end

@testset "Vector3f and Int32 multiplication" begin
@test vec1 * int == Math.Vector3f(4.0, 6.0, 8.0)
end

@testset "Vector3f and Float64 multiplication" begin
@test vec1 * float == Math.Vector3f(3.0, 4.5, 6.0)
end

@testset "Float64 and Vector3f multiplication" begin
@test float * vec1 == Math.Vector3f(3.0, 4.5, 6.0)
end
end

@testset "Vector3f division" begin
vec1 = Math.Vector3f(6.0, 8.0, 10.0)

@test vec1 / 2 == Math.Vector3f(3.0, 4.0, 5.0)
@test vec1 / 2.0 == Math.Vector3f(3.0, 4.0, 5.0)
end
end

@testset "Vector4 tests" begin
# set up
vec1 = Math.Vector4(2, 2, 2, 2)
vec2 = Math.Vector4(2) # 2, 2, 2, 2

@testset "Vector4 subtraction" begin
res = vec1 - vec2
@test res == Math.Vector4(0, 0, 0, 0)
end

@testset "Vector4 addition" begin
res = vec1 + vec2
@test res == Math.Vector4(4, 4, 4, 4)
end

@testset "Vector4 multiplication" begin
res = vec1 * vec2
@test res == Math.Vector4(4, 4, 4, 4)
end

@testset "Vector4 division" begin
res = vec1 / vec2
@test res == Math.Vector4(1, 1, 1, 1)
end

@testset "Vector4 constructor with Int32 and Float64 arguments" begin
v = Math.Vector4(2, 3.7, 4, 5.9)
@test v.x == 2
@test v.y == 4
@test v.z == 4
@test v.t == 6

v = Math.Vector4(-1, -5.9, -2, -7.9)
@test v.x == -1
@test v.y == -6
@test v.z == -2
@test v.t == -8
end

@testset "Vector4 constructor with Float64 and Int32 arguments" begin
v = Math.Vector4(1.5, 4, 5.9, 6)
@test v.x == 2
@test v.y == 4
@test v.z == 6
@test v.t == 6

v = Math.Vector4(-3.2, -7, -8.9, -9)
@test v.x == -3
@test v.y == -7
@test v.z == -9
@test v.t == -9
end

@testset "Vector4 multiplication with Int32" begin
vec = Math.Vector4(2, 3, 4, 5)
int::Int32 = 2
expected = Math.Vector4(4, 6, 8, 10)
@test vec * int == expected
end

@testset "Vector4 multiplication with Float64" begin
vec = Math.Vector4(2, 3, 4, 5)
float::Float64 = 1.5
expected = Math.Vector4(3.0, 4.5, 6.0, 7.5)
@test vec * float == expected
end

@testset "Float64 multiplication with Vector4" begin
float = 1.5
vec = Math.Vector4(2, 3, 4, 5)
expected = Math.Vector4(3.0, 4.5, 6.0, 7.5)
@test float * vec == expected
end

@testset "Vector4 division with Float64" begin
vec = Math.Vector4(6, 8, 10, 12)
float = 2.0
expected = Math.Vector4(3.0, 4.0, 5.0, 6.0)
@test vec / float == expected
end
end

@testset "Vector4f tests" begin
@testset "Vector4f constructors" begin
@test Math.Vector4f(1.0, 2.0, 3.0, 4.0) == Math.Vector4f(1.0, 2.0, 3.0, 4.0)
@test Math.Vector4f(1, 2, 3, 4) == Math.Vector4f(1.0, 2.0, 3.0, 4.0)
@test Math.Vector4f(1.5, 2, 3, 4) == Math.Vector4f(1.5, 2.0, 3.0, 4.0)
@test Math.Vector4f(1, 2.5, 3, 4) == Math.Vector4f(1.0, 2.5, 3.0, 4.0)
@test Math.Vector4f(1, 2, 3.5, 4) == Math.Vector4f(1.0, 2.0, 3.5, 4.0)
@test Math.Vector4f(1, 2, 3, 4.5) == Math.Vector4f(1.0, 2.0, 3.0, 4.5)
end

@testset "Vector4f addition" begin
vec1 = Math.Vector4f(1.0, 2.0, 3.0, 4.0)
vec2 = Math.Vector4f(5.0, 6.0, 7.0, 8.0)
@test vec1 + vec2 == Math.Vector4f(6.0, 8.0, 10.0, 12.0)
@test vec1 + 2 == Math.Vector4f(3.0, 4.0, 5.0, 6.0)
@test vec1 + 2.0 == Math.Vector4f(3.0, 4.0, 5.0, 6.0)
@test 2 + vec1 == Math.Vector4f(3.0, 4.0, 5.0, 6.0)
@test 2.0 + vec1 == Math.Vector4f(3.0, 4.0, 5.0, 6.0)
end

@testset "Vector4f subtraction" begin
vec1 = Math.Vector4f(1.0, 2.0, 3.0, 4.0)
vec2 = Math.Vector4f(5.0, 6.0, 7.0, 8.0)
@test vec1 - vec2 == Math.Vector4f(-4.0, -4.0, -4.0, -4.0)
@test vec1 - 2 == Math.Vector4f(-1.0, 0.0, 1.0, 2.0)
@test vec1 - 2.0 == Math.Vector4f(-1.0, 0.0, 1.0, 2.0)
@test 2 - vec1 == Math.Vector4f(1.0, 0.0, -1.0, -2.0)
@test 2.0 - vec1 == Math.Vector4f(1.0, 0.0, -1.0, -2.0)
end

@testset "Vector4f multiplication" begin
vec1 = Math.Vector4f(1.0, 2.0, 3.0, 4.0)
vec2 = Math.Vector4f(5.0, 6.0, 7.0, 8.0)
int = 2
float = 1.5

@testset "Vector4f and Vector4f multiplication" begin
@test vec1 * vec2 == Math.Vector4f(5.0, 12.0, 21.0, 32.0)
end

@testset "Vector4f and Int32 multiplication" begin
@test vec1 * int == Math.Vector4f(2.0, 4.0, 6.0, 8.0)
end

@testset "Vector4f and Float64 multiplication" begin
@test vec1 * float == Math.Vector4f(1.5, 3.0, 4.5, 6.0)
end

@testset "Float64 and Vector4f multiplication" begin
@test float * vec1 == Math.Vector4f(1.5, 3.0, 4.5, 6.0)
end
end

@testset "Vector4f division" begin
vec1 = Math.Vector4f(6.0, 8.0, 10.0, 12.0)
float = 2.0
@test vec1 / 2 == Math.Vector4f(3.0, 4.0, 5.0, 6.0)
@test vec1 / 2.0 == Math.Vector4f(3.0, 4.0, 5.0, 6.0)
end
end
end
10 changes: 10 additions & 0 deletions test/projects/SmokeTest/scripts/TestScript.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module TestScriptModule
@testset "Entity constructor" begin
newEntity = JulGame.EntityModule.Entity()
@test newEntity != C_NULL && newEntity !== nothing
push!(MAIN.scene.entities, newEntity)
end

@testset "Entity addAnimator" begin
Expand Down Expand Up @@ -97,6 +98,15 @@ module TestScriptModule
end
end

@testset "Scene api tests" begin
@test JulGame.SceneModule.get_entity_by_id(MAIN.scene, "test") === nothing
@test JulGame.SceneModule.get_entity_by_id(MAIN.scene, newEntity.id) == newEntity
@test JulGame.SceneModule.get_entity_by_name(MAIN.scene, "test") === nothing
@test JulGame.SceneModule.get_entity_by_name(MAIN.scene, newEntity.name) == newEntity
@test JulGame.SceneModule.get_entities_by_name(MAIN.scene, "test") == []
@test JulGame.SceneModule.get_entities_by_name(MAIN.scene, newEntity.name) == [newEntity]
end

@testset "UI Tests" begin
@testset "ScreenButton constructor" begin

Expand Down

0 comments on commit f659ed0

Please sign in to comment.