Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
306
306Ass5
Commits
946daa09
Commit
946daa09
authored
Mar 25, 2019
by
michael lundquist
Browse files
Spiffing up these methods and adding tests for them
parent
e0b21e2c
Changes
3
Show whitespace changes
Inline
Side-by-side
fifthassignment/src/main/java/com/ds/fifthassignment/LinkedListStack.java
View file @
946daa09
...
@@ -69,7 +69,7 @@ public class LinkedListStack implements Iterable{
...
@@ -69,7 +69,7 @@ public class LinkedListStack implements Iterable{
public
int
search
(
Object
o
){
public
int
search
(
Object
o
){
int
distance
=
0
;
int
distance
=
0
;
//search for the element and increment distance
//search for the element and increment distance
Iterator
it
=
this
.
i
terator
();
Iterator
<
Object
>
it
=
this
.
data
.
descendingI
terator
();
Object
testObject
=
null
;
Object
testObject
=
null
;
while
(
it
.
hasNext
()){
while
(
it
.
hasNext
()){
distance
++;
distance
++;
...
...
fifthassignment/src/main/java/com/ds/fifthassignment/Stack.java
View file @
946daa09
...
@@ -69,7 +69,8 @@ public class Stack {
...
@@ -69,7 +69,8 @@ public class Stack {
//search for the element and increment distance
//search for the element and increment distance
Node
test
=
this
.
top
;
Node
test
=
this
.
top
;
while
(
test
!=
null
){
while
(
test
!=
null
){
if
(
test
.
data
.
equals
(
o
)){
boolean
result
=
test
.
data
.
equals
(
o
);
if
(
result
){
return
distance
;
return
distance
;
}
}
distance
++;
distance
++;
...
...
fifthassignment/src/test/java/com/ds/fifthassignment/AppTest.java
View file @
946daa09
...
@@ -3,18 +3,167 @@ package com.ds.fifthassignment;
...
@@ -3,18 +3,167 @@ package com.ds.fifthassignment;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.junit.Test
;
import
org.junit.Test
;
import
javax.swing.JOptionPane
;
/**
/**
* Unit test for simple App.
* Unit test for simple App.
*/
*/
public
class
AppTest
public
class
AppTest
{
{
public
static
void
main
(
String
[]
args
){
int
test
=
4
;
Stack
s
=
new
Stack
();
for
(
int
k
=
1
;
k
<=
10
;
k
++){
if
(
k
==
test
){
s
.
push
(
"b"
);
}
else
{
s
.
push
(
"a"
);
}
}
JOptionPane
.
showMessageDialog
(
null
,
"the value of test is: "
+
test
);
System
.
out
.
println
(
"the search value is: "
+
s
.
search
(
"b"
));
}
/**
* Tests the stack peek function
*/
@Test
public
void
testStackPeek
(){
Integer
test
=
randRange
(
0
,
100
);
Integer
randomStop
=
randRange
(
5
,
10
);
Stack
s
=
new
Stack
();
for
(
int
k
=
0
;
k
<
randomStop
;
k
++){
test
=
new
Integer
(
randRange
(
0
,
100
));
s
.
push
(
test
);
}
assertTrue
(
s
.
peek
().
equals
(
test
));
}
/**
/**
*
Rigorous Test :-)
*
Tests the stack peek function
*/
*/
@Test
@Test
public
void
shouldAnswerWithTrue
()
public
void
test_LL_StackPeek
(){
{
Integer
test
=
randRange
(
0
,
100
);
assertTrue
(
true
);
Integer
randomStop
=
randRange
(
5
,
10
);
LinkedListStack
s
=
new
LinkedListStack
();
for
(
int
k
=
0
;
k
<
randomStop
;
k
++){
test
=
new
Integer
(
randRange
(
0
,
100
));
s
.
push
(
test
);
}
assertTrue
(
s
.
peek
().
equals
(
test
));
}
/**
* Tests the stack peek function
*/
@Test
public
void
testStackSearch
(){
//Integer test = randRange(1,10);
int
test
=
4
;
Stack
s
=
new
Stack
();
for
(
int
k
=
1
;
k
<=
10
;
k
++){
if
(
k
==
test
){
s
.
push
(
"b"
);
}
else
{
s
.
push
(
"a"
);
}
}
//JOptionPane.showMessageDialog(null, "the value of test is: " + (11 - test) );
//JOptionPane.showMessageDialog(null, "The search result: " + s.search("b"));
assertTrue
(
s
.
search
(
"b"
)
==
(
11
-
test
));
//assertTrue(false);
}
/**
* Tests the stack peek function
*/
@Test
public
void
test_LL_StackSearch
(){
//Integer test = randRange(1,10);
int
test
=
4
;
JOptionPane
.
showMessageDialog
(
null
,
"hi"
);
LinkedListStack
s
=
new
LinkedListStack
();
for
(
int
k
=
1
;
k
<=
10
;
k
++){
if
(
k
==
test
){
s
.
push
(
"b"
);
}
else
{
s
.
push
(
"a"
);
}
}
JOptionPane
.
showMessageDialog
(
null
,
"the value of test is: "
+
(
11
-
test
)
);
JOptionPane
.
showMessageDialog
(
null
,
"The search result: "
+
s
.
search
(
"b"
));
assertTrue
(
s
.
search
(
"b"
)
==
(
11
-
test
));
//assertTrue(false);
}
/**
* Tests the stack peek function
*/
@Test
public
void
testArrayStackSearch
(){
//Integer test = randRange(1,10);
int
test
=
4
;
JOptionPane
.
showMessageDialog
(
null
,
"hi"
);
ArrayStack
s
=
new
ArrayStack
();
for
(
int
k
=
1
;
k
<=
10
;
k
++){
if
(
k
==
test
){
s
.
push
(
"b"
);
}
else
{
s
.
push
(
"a"
);
}
}
JOptionPane
.
showMessageDialog
(
null
,
"the value of test is: "
+
(
11
-
test
)
);
JOptionPane
.
showMessageDialog
(
null
,
"The search result: "
+
s
.
search
(
"b"
));
assertTrue
(
s
.
search
(
"b"
)
==
(
11
-
test
));
//assertTrue(false);
}
/**
* Tests the stack peek function
*/
@Test
public
void
testQueueElement
(){
assertTrue
(
true
);
}
/**
* Tests the stack peek function
*/
@Test
public
void
test_LL_QueueElement
(){
assertTrue
(
true
);
}
/**
* Tests the stack peek function
*/
@Test
public
void
testArrayQueueOffer
(){
assertTrue
(
true
);
}
/**
* Tests the stack peek function
*/
@Test
public
void
testIsValid
(){
assertTrue
(
true
);
}
/**
* gets a random number between max and min
*
* @param max
* @param min
* @return
*/
public
static
Integer
randRange
(
int
max
,
int
min
){
return
min
+
(
int
)(
Math
.
random
()
*
((
max
-
min
)
+
1
));
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment