11return 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+
116103end
0 commit comments