FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/annotations/AtUnitExample4.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
annotations
/
AtUnitExample4.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (81 loc) · 2.24 KB
Breadcrumbs
OnJava8-Examples
/
annotations
/
AtUnitExample4.java
Copy path
File metadata and controls
83 lines (81 loc) · 2.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// annotations/AtUnitExample4.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// {java onjava.atunit.AtUnit
// build/classes/java/main/annotations/AtUnitExample4.class}
// {VisuallyInspectOutput}
package
annotations
;
import
java
.
util
.*;
import
onjava
.
atunit
.*;
import
onjava
.*;
public
class
AtUnitExample4
{
static
String
theory
=
"All brontosauruses "
+
"are thin at one end, much MUCH thicker in the "
+
"middle, and then thin again at the far end."
;
private
String
word
;
private
Random
rand
=
new
Random
();
// Time-based seed
public
AtUnitExample4
(
String
word
) {
this
.
word
=
word
;
}
public
String
getWord
() {
return
word
; }
public
String
scrambleWord
() {
List
<
Character
>
chars
=
Arrays
.
asList
(
ConvertTo
.
boxed
(
word
.
toCharArray
()));
Collections
.
shuffle
(
chars
,
rand
);
StringBuilder
result
=
new
StringBuilder
();
for
(
char
ch
:
chars
)
result
.
append
(
ch
);
return
result
.
toString
();
}
@
TestProperty
static
List
<
String
>
input
=
Arrays
.
asList
(
theory
.
split
(
" "
));
@
TestProperty
static
Iterator
<
String
>
words
=
input
.
iterator
();
@
TestObjectCreate
static
AtUnitExample4
create
() {
if
(
words
.
hasNext
())
return
new
AtUnitExample4
(
words
.
next
());
else
return
null
;
}
@
Test
boolean
words
() {
System
.
out
.
println
(
"'"
+
getWord
() +
"'"
);
return
getWord
().
equals
(
"are"
);
}
@
Test
boolean
scramble1
() {
// Use specific seed to get verifiable results:
rand
=
new
Random
(
47
);
System
.
out
.
println
(
"'"
+
getWord
() +
"'"
);
String
scrambled
=
scrambleWord
();
System
.
out
.
println
(
scrambled
);
return
scrambled
.
equals
(
"lAl"
);
}
@
Test
boolean
scramble2
() {
rand
=
new
Random
(
74
);
System
.
out
.
println
(
"'"
+
getWord
() +
"'"
);
String
scrambled
=
scrambleWord
();
System
.
out
.
println
(
scrambled
);
return
scrambled
.
equals
(
"tsaeborornussu"
);
}
}
/* Output:
annotations.AtUnitExample4
. words 'All'
(failed)
. scramble1 'brontosauruses'
ntsaueorosurbs
(failed)
. scramble2 'are'
are
(failed)
(3 tests)
>>> 3 FAILURES <<<
annotations.AtUnitExample4: words
annotations.AtUnitExample4: scramble1
annotations.AtUnitExample4: scramble2
*/
Back
|
FazBrowse Home
|
New Git URL