/
DeepDive05Recursion.java
124 lines (121 loc) · 3.41 KB
/
DeepDive05Recursion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package org.teachingkidsprogramming.recipes.completed.section05recursion;
import org.junit.Assert;
import org.junit.Test;
import org.teachingextensions.logo.Tortoise;
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
import java.awt.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class DeepDive05Recursion
{
@Test
public void changeThePointerToAHand() throws Exception
{
Tortoise.getBackgroundWindow().setCursor(Cursor.HAND_CURSOR);
Assert.assertEquals(getCursor(), Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
@Test
public void getTheWindow() throws Exception
{
Tortoise.getBackgroundWindow().setCursor(Cursor.CROSSHAIR_CURSOR);
Assert.assertEquals(getCursor(), Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}
@Test
public void setColorUsingKey() throws Exception
{
HashMap<Integer, Color> colors = new HashMap<Integer, Color>();
colors.put(10, PenColors.Greens.Lime);
colors.put(20, PenColors.Greens.DarkGreen);
Assert.assertEquals(PenColors.Greens.DarkGreen, colors.get(20));
}
@Test
public void findTheGreenKey() throws Exception
{
HashMap<Integer, Color> colors = new HashMap<Integer, Color>();
colors.put(20, PenColors.Greens.DarkGreen);
colors.put(30, PenColors.Greens.Green);
Assert.assertEquals(PenColors.Greens.Green, colors.get(30));
}
@Test
public void findTheColorForTheBananaKey() throws Exception
{
HashMap<String, Color> colors = new HashMap<String, Color>();
colors.put("banana", PenColors.Yellows.Yellow);
colors.put("apple", PenColors.Reds.Red);
Assert.assertEquals(PenColors.Yellows.Yellow, colors.get("banana"));
}
@Test
public void findTheNumberPositionOfTheWorld() throws Exception
{
List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
String result = messages.get(1);
Assert.assertEquals("World!", result);
}
@Test
public void getWhatsLast() throws Exception
{
List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
String result = messages.get(4);
Assert.assertEquals("You", result);
}
@Test
public void whatIsLastNow() throws Exception
{
List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
messages.set(4, "The rest of them");
String result = messages.get(4);
Assert.assertEquals("The rest of them", result);
}
@Test
public void putAQuarterAtTheEnd() throws Exception
{
int[] coins = {1, 5, 10, 25};
Assert.assertEquals(25, coins[3]);
}
@Test
public void getThirdCoin() throws Exception
{
int[] coins = {1, 5, 10, 25};
Assert.assertEquals(10, coins[2]);
}
@Test
public void whichCoinIsSecond() throws Exception
{
int[] coins = {1, 5, 10, 25};
Assert.assertEquals(5, coins[1]);
}
@Test
public void putAFiftyCentPieceFirst() throws Exception
{
int[] coins = {1, 5, 10, 25};
coins[0] = 50;
Assert.assertEquals(50, coins[0]);
}
/**
* Ignore the following, It's needed to run the deep dive
*
*
*
*
*
*
*
*
*
*
*/
public boolean _____ = false;
public boolean ______ = true;
public String ___ = "You need to fill in the blank ___";
public int ____ = 0;
public Color _______;
public String ___()
{
return ___;
}
private Cursor getCursor()
{
return Tortoise.getBackgroundWindow().getCanvas().getCursor();
}
}