1 | using Jypeli; |
---|
2 | using Jypeli.Assets; |
---|
3 | using Jypeli.Controls; |
---|
4 | using Jypeli.Effects; |
---|
5 | using Jypeli.Widgets; |
---|
6 | using AdvanceMath; |
---|
7 | using System; |
---|
8 | |
---|
9 | namespace Pallospeli |
---|
10 | { |
---|
11 | /// <summary> |
---|
12 | /// Pienet testaukset, kun en jaksanut asennella mitään testaustyökaluja. |
---|
13 | /// Ei mitenkään täydelliset testit. |
---|
14 | /// </summary> |
---|
15 | public class Testaus |
---|
16 | { |
---|
17 | /// <summary> |
---|
18 | /// Palauttaa true, jos kaikki testit menee läpi |
---|
19 | /// </summary> |
---|
20 | /// <returns></returns> |
---|
21 | public static bool Run() |
---|
22 | { |
---|
23 | if (!testRepairBallLocations()) return false; |
---|
24 | if (!testGet()) return false; |
---|
25 | if (!testGetNear()) return false; |
---|
26 | |
---|
27 | return true; |
---|
28 | } |
---|
29 | |
---|
30 | public static bool testRepairBallLocations() |
---|
31 | { |
---|
32 | Ball[] bls = { null, new Ball(Color.Aqua), new Ball(Color.Aqua), null, new Ball(Color.Aqua) }; |
---|
33 | Ball[] bls2 = { new Ball(Color.Aqua), new Ball(Color.Aqua), null, new Ball(Color.Aqua) }; |
---|
34 | Ball[] bls3 = { new Ball(Color.Aqua), null, null, new Ball(Color.Aqua), null }; |
---|
35 | |
---|
36 | Ball[][] blssls = new Ball[3][]; |
---|
37 | blssls[0] = bls; |
---|
38 | blssls[1] = bls2; |
---|
39 | blssls[2] = bls3; |
---|
40 | Playfield pl = new Playfield(blssls); |
---|
41 | pl.RepairBallLocations(); |
---|
42 | |
---|
43 | if (pl.Balls[0][1].Location.X != 1 || pl.Balls[0][1].Location.Y != 0) return false; |
---|
44 | if (pl.Balls[0][2].Location.X != 2 || pl.Balls[0][2].Location.Y != 0) return false; |
---|
45 | if (pl.Balls[0][4].Location.X != 4 || pl.Balls[0][4].Location.Y != 0) return false; |
---|
46 | if (pl.Balls[1][0].Location.X != 0 || pl.Balls[1][0].Location.Y != 1) return false; |
---|
47 | if (pl.Balls[1][1].Location.X != 1 || pl.Balls[1][1].Location.Y != 1) return false; |
---|
48 | if (pl.Balls[1][3].Location.X != 3 || pl.Balls[1][3].Location.Y != 1) return false; |
---|
49 | if (pl.Balls[2][0].Location.X != 0 || pl.Balls[2][0].Location.Y != 2) return false; |
---|
50 | if (pl.Balls[2][3].Location.X != 3 || pl.Balls[2][3].Location.Y != 2) return false; |
---|
51 | |
---|
52 | return true; |
---|
53 | } |
---|
54 | |
---|
55 | public static bool testGet() |
---|
56 | { |
---|
57 | Ball[] bls = { new Ball(Color.Aqua), new Ball(Color.Aqua), new Ball(Color.Aqua), null, new Ball(Color.Aqua) }; |
---|
58 | Ball[] bls2 = { new Ball(Color.Aqua), new Ball(Color.Aqua), null, new Ball(Color.Aqua) }; |
---|
59 | Ball[] bls3 = { new Ball(Color.Aqua), null, null, new Ball(Color.Aqua), null }; |
---|
60 | |
---|
61 | Ball[][] blssls = new Ball[3][]; |
---|
62 | blssls[0] = bls; |
---|
63 | blssls[1] = bls2; |
---|
64 | blssls[2] = bls3; |
---|
65 | Playfield pl = new Playfield(blssls); |
---|
66 | |
---|
67 | if (pl.Get(2, 0) == null) return false; |
---|
68 | if (pl.Get(-3, 0) != null) return false; |
---|
69 | if (pl.Get(5, 0) != null) return false; |
---|
70 | if (pl.Get(4, 0) == null) return false; |
---|
71 | if (pl.Get(0, 0) == null) return false; |
---|
72 | |
---|
73 | if (pl.Get(1, 4) != null) return false; |
---|
74 | |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
78 | public static bool testGetNear() |
---|
79 | { |
---|
80 | Ball[] bls = { new Ball(Color.Aqua), new Ball(Color.Aqua), new Ball(Color.Aqua), null, new Ball(Color.Aqua) }; |
---|
81 | Ball[] bls2 = { new Ball(Color.Aqua), new Ball(Color.Cyan), null, new Ball(Color.Aqua) }; |
---|
82 | Ball[] bls3 = { new Ball(Color.Aqua), null, null, new Ball(Color.Aqua), null }; |
---|
83 | |
---|
84 | Ball[][] blssls = new Ball[3][]; |
---|
85 | blssls[0] = bls; |
---|
86 | blssls[1] = bls2; |
---|
87 | blssls[2] = bls3; |
---|
88 | Playfield pl = new Playfield(blssls); |
---|
89 | |
---|
90 | if (pl.GetNear(new Location(1, 1)).Count != 3) return false; |
---|
91 | if (pl.GetNear(new Location(0, 0)).Count != 2) return false; |
---|
92 | |
---|
93 | return true; |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|