Skip to content

Commit ce4e2b6

Browse files
authored
Rewrite tests (#8)
2 parents 756e891 + 4ceea44 commit ce4e2b6

File tree

3 files changed

+81
-105
lines changed

3 files changed

+81
-105
lines changed

.github/workflows/docs.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: Docs
33
on:
44
workflow_dispatch:
55

6-
pull_request:
7-
branches:
8-
- "main"
9-
106
jobs:
117
build:
128
name: Deploy docs

src/SimplePath.lua

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,11 @@ function Path:Destroy()
241241
if rawget(self, "Visualize") then
242242
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
243243
end
244-
self._agent = nil
245-
self._humanoid = nil
246244
self._path:Destroy()
247-
self._path =nil
248-
self._status = nil
249-
self._t = nil
250-
self._position = nil
251-
self._target = nil
252-
self._waypoints = nil
253-
self._currentWaypoint = nil
254-
self._lastError = nil
255245
setmetatable(self, nil)
246+
for k, _ in pairs(self) do
247+
self[k] = nil
248+
end
256249
end
257250

258251
function Path:Stop()

src/SimplePath.spec.lua

Lines changed: 78 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,103 @@
11
return function()
2-
2+
33
local SimplePath = require(game:GetService("ReplicatedStorage").SimplePath)
44
local Dummy = workspace.Dummy
55
local Goal = workspace.Goal
6-
local Path = SimplePath.new(Dummy)
7-
8-
-- selene: allow(unused_variable)
9-
local reached, errored, stopped
10-
local waypointsReached = 0
11-
12-
Path.Reached:Connect(function()
13-
reached = true
14-
end)
15-
16-
Path.Error:Connect(function()
17-
errored = true
18-
end)
19-
20-
Path.WaypointReached:Connect(function()
21-
waypointsReached += 1
22-
end)
23-
24-
Path.Stopped:Connect(function()
25-
stopped = true
6+
local Path
7+
8+
describe("constructor", function()
9+
10+
it("creates a new Path with provided character", function()
11+
expect(SimplePath.new(Dummy)).to.be.ok()
12+
end)
13+
14+
it("errors when model is not passed in", function()
15+
expect(function()
16+
SimplePath.new()
17+
end).to.throw()
18+
end)
19+
20+
it("errors when PrimaryPart is not set", function()
21+
expect(function()
22+
local c = Dummy:Clone()
23+
c.PrimaryPart = nil
24+
SimplePath.new(c)
25+
end).to.throw()
26+
end)
27+
28+
it("overrides default settings", function()
29+
local config = SimplePath.new(Dummy, nil, {
30+
TIME_VARIANCE = 2;
31+
COMPARISON_CHECKS = 2;
32+
JUMP_WHEN_STUCK = false;
33+
})._settings
34+
local defaults = {
35+
TIME_VARIANCE = 0.07;
36+
COMPARISON_CHECKS = 1;
37+
JUMP_WHEN_STUCK = true;
38+
}
39+
expect(function()
40+
for i, v in pairs(config) do
41+
if defaults[i] == v then
42+
error("Does not override default settings")
43+
end
44+
end
45+
end).never.to.throw()
46+
end)
47+
2648
end)
27-
28-
local function reset()
29-
Dummy.PrimaryPart.CFrame = CFrame.new(0, 3, 0)
30-
if Path.Status == SimplePath.StatusType.Active then
31-
Path:Stop()
32-
end
33-
end
34-
35-
local function getCount(t)
36-
local c = 0
37-
for _, _ in pairs(t) do
38-
c += 1
39-
end
40-
return c
41-
end
42-
49+
4350
describe("Path:Run()", function()
4451

45-
-- local t
46-
47-
-- beforeAll(function()
48-
-- t = os.time()
49-
-- end)
50-
51-
afterAll(function()
52-
reset()
53-
task.wait(1)
52+
beforeAll(function()
53+
Path = SimplePath.new(Dummy)
5454
end)
55-
56-
it("should start pathfinding without errors", function()
57-
expect(Path:Run(Goal)).to.be.ok()
55+
56+
it("errors if no valid Vector3 or BasePart is given", function()
57+
expect(function()
58+
Path:Run()
59+
end).to.throw()
5860
end)
59-
60-
it("should change state to active when pathfinding", function()
61-
Path:Run(Goal)
62-
expect(Path.Status).to.equal(SimplePath.StatusType.Active)
61+
62+
it("should change Path.Status to StatusType.Active", function()
63+
expect(Path.Status == SimplePath.StatusType.Active).to.be.ok()
6364
end)
64-
65-
-- it("should fire Path.Reached after reaching goal", function()
66-
-- repeat
67-
-- task.wait()
68-
-- until reached or os.difftime(os.time(), t) > 4
69-
-- print("Position: ", os.difftime(os.time(), t), Dummy.PrimaryPart.Position)
70-
-- expect(reached).to.be.ok()
71-
-- end)
72-
73-
-- it("should reach all the waypoints to goal", function()
74-
-- print("Total Waypoints: ", waypointsReached)
75-
-- expect(waypointsReached).to.equal(7)
76-
-- end)
77-
65+
66+
it("should return true", function()
67+
expect(Path:Run(Goal)).to.be.ok()
68+
end)
69+
7870
end)
7971

72+
8073
describe("Path:Stop()", function()
81-
82-
local midPos
83-
8474
beforeAll(function()
85-
Path:Run(Goal)
86-
task.wait(1)
8775
Path:Stop()
88-
task.wait(1)
89-
midPos = Dummy.PrimaryPart.Position
90-
task.wait(1)
91-
end)
92-
93-
it("should stop pathfinding", function()
94-
expect(midPos).to.equal(Dummy.PrimaryPart.Position)
9576
end)
96-
97-
it("should fire Path.Stopped", function()
98-
expect(stopped).to.be.ok()
77+
it("should change Path.Status to StatusType.Idle", function()
78+
expect(Path.Status == SimplePath.StatusType.Idle).to.be.ok()
9979
end)
100-
101-
it("should change state back to idle", function()
102-
expect(Path.Status).to.equal(SimplePath.StatusType.Idle)
80+
end)
81+
82+
describe("test", function()
83+
it("should not produce any ErrorType", function()
84+
expect(Path.LastError).never.to.be.ok()
10385
end)
104-
10586
end)
10687

10788
describe("Path:Destroy()", function()
108-
109-
it("should destroy Path", function()
89+
beforeAll(function()
11090
Path:Destroy()
111-
expect(getCount(Path)).to.equal(0)
11291
end)
113-
92+
93+
it("should destroy Path", function()
94+
expect(function()
95+
for k, _ in pairs(Path) do
96+
error(("Path.%s exists!"):format(k))
97+
end
98+
end).never.to.throw()
99+
expect(getmetatable(Path)).never.to.be.ok()
100+
end)
114101
end)
115-
102+
116103
end

0 commit comments

Comments
 (0)