1 |
|
package alitest; |
2 |
|
|
3 |
|
import fi.jyu.mit.ohj2.*; |
4 |
|
import java.io.*; |
5 |
|
import java.util.*; |
6 |
|
import static fi.jyu.mit.ohj2.VertaaTiedosto.*; |
7 |
|
import static org.junit.Assert.*; |
8 |
|
import org.junit.*; |
9 |
|
import static fi.jyu.mit.ohj2.Suuntaaja.*; |
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
@version |
15 |
|
|
16 |
|
|
17 |
|
@SuppressWarnings({ "PMD" }) |
|
|
| 100% |
Uncovered Elements: 0 (96) |
Complexity: 8 |
Complexity Density: 0,09 |
|
18 |
|
public class SuuntaajaTest { |
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
@throws |
26 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
27 |
1
|
@Test... |
28 |
|
public void testInNimi82() throws IOException { |
29 |
1
|
kirjoitaTiedosto("hiljaa1.txt", "33 hiljaa 1 hiipii\nhyvä 33 tulee\n"); |
30 |
1
|
Input in = new Input("hiljaa1.txt"); |
31 |
1
|
Scanner sc = new Scanner(System.in); |
32 |
1
|
assertEquals("From: Suuntaaja line: 90", "33 hiljaa 1 hiipii", sc.nextLine()); |
33 |
1
|
assertEquals("From: Suuntaaja line: 91", "hyvä 33 tulee", sc.nextLine()); |
34 |
1
|
assertEquals("From: Suuntaaja line: 92", false, sc.hasNextLine()); |
35 |
1
|
in.palauta(); |
36 |
1
|
tuhoaTiedosto("hiljaa1.txt"); |
37 |
1
|
in = new Input(null); |
38 |
1
|
in.palauta(); |
39 |
|
} |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@throws |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0,12 |
1
PASS
|
|
47 |
1
|
@Test... |
48 |
|
public void testOutNimi137() throws IOException { |
49 |
1
|
Output out = new Output("hiljaa1.txt"); |
50 |
1
|
System.out.println("eka"); |
51 |
1
|
System.out.println("toka"); |
52 |
1
|
out.palauta(); |
53 |
1
|
assertEquals("From: Suuntaaja line: 146", null, vertaaFileString("hiljaa1.txt","eka\ntoka\n")); |
54 |
1
|
tuhoaTiedosto("hiljaa1.txt"); |
55 |
1
|
out = new Output(null); |
56 |
1
|
out.palauta(); |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0,09 |
1
PASS
|
|
62 |
1
|
@Test... |
63 |
|
public void testStringInput178() { |
64 |
1
|
StringInput si = new StringInput("kissa\nkoira"); |
65 |
1
|
StringOutput so = new StringOutput(); |
66 |
1
|
assertEquals("From: Suuntaaja line: 181", "kissa", Syotto.kysy("Mikä")); |
67 |
1
|
assertEquals("From: Suuntaaja line: 182", "koira", Syotto.kysy("Mikä")); |
68 |
1
|
assertEquals("From: Suuntaaja line: 183", "", Syotto.kysy("Mikä")); |
69 |
1
|
si = new StringInput("12\n13"); |
70 |
1
|
assertEquals("From: Suuntaaja line: 185", 12, Syotto.kysy("Luku",0)); |
71 |
1
|
assertEquals("From: Suuntaaja line: 186", 13, Syotto.kysy("Luku",0)); |
72 |
1
|
assertEquals("From: Suuntaaja line: 187", 0, Syotto.kysy("Luku",0)); |
73 |
1
|
si.palauta(); |
74 |
1
|
so.palauta(); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0,09 |
1
PASS
|
|
80 |
1
|
@Test... |
81 |
|
public void testInput218() { |
82 |
1
|
StringInput si = new StringInput("kissa\nkoira"); |
83 |
1
|
StringOutput so = new StringOutput(); |
84 |
1
|
assertEquals("From: Suuntaaja line: 221", "kissa", Syotto.kysy("Mikä")); |
85 |
1
|
assertEquals("From: Suuntaaja line: 222", "koira", Syotto.kysy("Mikä")); |
86 |
1
|
assertEquals("From: Suuntaaja line: 223", "", Syotto.kysy("Mikä")); |
87 |
1
|
si.input("12\n13"); |
88 |
1
|
assertEquals("From: Suuntaaja line: 225", 12, Syotto.kysy("Luku",0)); |
89 |
1
|
assertEquals("From: Suuntaaja line: 226", 13, Syotto.kysy("Luku",0)); |
90 |
1
|
assertEquals("From: Suuntaaja line: 227", 0, Syotto.kysy("Luku",0)); |
91 |
1
|
si.palauta(); |
92 |
1
|
so.palauta(); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
98 |
1
|
@Test... |
99 |
|
public void testToString270() { |
100 |
1
|
String NL = getNL(); |
101 |
1
|
StringOutput so = new StringOutput(); |
102 |
1
|
System.out.println("eka"); |
103 |
1
|
System.out.println("toka"); |
104 |
1
|
assertEquals("From: Suuntaaja line: 275", "eka"+NL+"toka"+NL, so.toString()); |
105 |
1
|
System.out.println("kolmas"); |
106 |
1
|
assertEquals("From: Suuntaaja line: 277", "eka"+NL+"toka"+NL+"kolmas"+NL, so.toStringReset()); |
107 |
1
|
assertEquals("From: Suuntaaja line: 278", "", so.toString()); |
108 |
1
|
System.out.println("neljäs"); |
109 |
1
|
assertEquals("From: Suuntaaja line: 280", "neljäs"+NL, so.toStringReset()); |
110 |
1
|
System.out.print("viides\nkuudes"); |
111 |
1
|
assertEquals("From: Suuntaaja line: 282", "viides\nkuudes", so.toStringReset()); |
112 |
1
|
System.out.printf("viides%nkuudes"); |
113 |
1
|
assertEquals("From: Suuntaaja line: 284", "viides"+NL+"kuudes", so.toStringReset()); |
114 |
1
|
so.palauta(); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
@throws |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1
PASS
|
|
123 |
1
|
@Test... |
124 |
|
public void testWriteTo316() throws IOException { |
125 |
1
|
PrintStream fs = Tiedosto.avaa_kirjoittamista_varten_stream("hiljaa1.txt"); |
126 |
1
|
StringOutput so = new StringOutput(); |
127 |
1
|
System.out.println("eka"); |
128 |
1
|
System.out.println("toka"); |
129 |
1
|
so.writeTo(fs); |
130 |
1
|
fs.close(); |
131 |
1
|
so.palauta(); |
132 |
1
|
assertEquals("From: Suuntaaja line: 325", null, vertaaFileString("hiljaa1.txt","eka\ntoka\n")); |
133 |
1
|
tuhoaTiedosto("hiljaa1.txt"); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
139 |
1
|
@Test... |
140 |
|
public void testEro347() { |
141 |
1
|
StringOutput so = new StringOutput(); |
142 |
1
|
System.out.println("eka"); |
143 |
1
|
System.out.println("toka"); |
144 |
1
|
assertEquals("From: Suuntaaja line: 351", null, so.ero("eka\ntoka\n")); |
145 |
1
|
System.out.println("kolmas"); |
146 |
1
|
assertEquals("From: Suuntaaja line: 353", "Ero riveissä 1: kolmas ja eka", so.ero("eka\ntoka\nkolmas\n")); |
147 |
1
|
assertEquals("From: Suuntaaja line: 354", "", so.toString()); |
148 |
1
|
System.out.println("neljäs"); |
149 |
1
|
assertEquals("From: Suuntaaja line: 356", null, so.ero("neljäs\n")); |
150 |
1
|
System.out.print("viides\nkuudes"); |
151 |
1
|
assertEquals("From: Suuntaaja line: 358", null, so.ero("viides\nkuudes")); |
152 |
1
|
System.out.printf("viides%nkuudes"); |
153 |
1
|
assertEquals("From: Suuntaaja line: 360", null, so.ero("viides\nkuudes")); |
154 |
1
|
so.palauta(); |
155 |
1
|
assertEquals("From: Suuntaaja line: 362", true, so.getOrigOut() == System.out); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
@throws |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0,11 |
1
PASS
|
|
164 |
1
|
@Test... |
165 |
|
public void testInNimi389() throws IOException { |
166 |
1
|
kirjoitaTiedosto("hiljaa1.txt", "eka\ntoka\n"); |
167 |
1
|
InOut io = new InOut("hiljaa1.txt","hiljaa2.txt"); |
168 |
1
|
assertEquals("From: Suuntaaja line: 393", "eka", Syotto.kysy("1.")); |
169 |
1
|
assertEquals("From: Suuntaaja line: 394", "toka", Syotto.kysy("2.")); |
170 |
1
|
assertEquals("From: Suuntaaja line: 395", "", Syotto.kysy("3.")); |
171 |
1
|
io.palauta(); |
172 |
1
|
tuhoaTiedosto("hiljaa1.txt"); |
173 |
1
|
assertEquals("From: Suuntaaja line: 398", null, vertaaFileString("hiljaa2.txt","1. >2. >3. >")); |
174 |
1
|
tuhoaTiedosto("hiljaa2.txt"); |
175 |
|
} |
176 |
|
} |