-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeToBeTested.java
More file actions
77 lines (68 loc) · 1.66 KB
/
CodeToBeTested.java
File metadata and controls
77 lines (68 loc) · 1.66 KB
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
/**
* This class represents a sample of a piece of code being tested.
* The code here does not do anything interesting. The methods are
* only intended to demonstrate various testing scenarios.
*/
import java.lang.Math;
public class CodeToBeTested {
/**
* Member variable for checking side effects
*/
private boolean variableToChange = false;
/**
* Accessor for member variable
* @return value of variable
*/
public boolean getVariableToChange() {
return variableToChange;
}
/**
* Method for checking return values
* @param input
* @return
*/
public int addOne(int input) {
return input + 1;
}
/**
* Method for seeing challenges with precision
* @param d
* @return
*/
public double returnsHalf(double d) {
return d / 2.0;
}
/**
* Method for checking values of returned objects
* @return
*/
public CodeToBeTested returnsObject() {
return new CodeToBeTested();
}
/**
* Method for checking returned objects equals
* @return
*/
public String returnsString() {
return Boolean.toString(variableToChange);
}
/**
* Method to create a side effect
*/
public void modifyVariable() {
variableToChange = true;
}
/**
* Method that might throws an exception
* @param arg1
* @throws IllegalArgumentException if input is negative
* @return
*/
public int methodThrowsException(int arg1) {
if (arg1 < 0) {
throw new IllegalArgumentException();
} else {
return (int)(arg1 * Math.PI);
}
}
}