Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2023_9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kluge Svendsrud
idatt1002_2023_9
Commits
1cd18afa
Commit
1cd18afa
authored
2 years ago
by
Andreas
Browse files
Options
Downloads
Patches
Plain Diff
Made tests for ItemOverview class
parent
439388de
No related branches found
Branches containing commit
No related tags found
1 merge request
!4
ItemOverview class (with test class)
Pipeline
#202377
passed
2 years ago
Stage: build
Stage: test
Stage: package
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java
+6
-0
6 additions, 0 deletions
src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java
src/test/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java
+51
-0
51 additions, 0 deletions
...st/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java
with
57 additions
and
0 deletions
src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java
+
6
−
0
View file @
1cd18afa
...
...
@@ -39,6 +39,9 @@ public class ItemOverview {
* @param newIncome The Income you want to add.
*/
public
void
addIncome
(
Income
newIncome
){
if
(
income
.
contains
(
newIncome
)){
throw
new
IllegalArgumentException
(
"This income is already registered"
);
}
income
.
add
(
newIncome
);
}
...
...
@@ -47,6 +50,9 @@ public class ItemOverview {
* @param newExpense The Expense you want to add.
*/
public
void
addExpense
(
Expense
newExpense
){
if
(
expense
.
contains
(
newExpense
)){
throw
new
IllegalArgumentException
(
"This expense is already registered"
);
}
expense
.
add
(
newExpense
);
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java
0 → 100644
+
51
−
0
View file @
1cd18afa
package
no.ntnu.idatt1002.demo.data
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
public
class
ItemOverviewTest
{
ItemOverview
itemOverview
;
@BeforeEach
public
void
makeItemOverview
(){
itemOverview
=
new
ItemOverview
();
}
@Test
@DisplayName
(
"addIncome method throws exception when it should"
)
void
addIncomeThrows
(){
itemOverview
.
addIncome
(
new
Income
(
"description"
,
59.9f
,
false
,
IncomeCategory
.
SALARY
,
"03.03.23"
));
itemOverview
.
addIncome
(
new
Income
(
"description"
,
59.9f
,
false
,
IncomeCategory
.
SALARY
,
"03.03.23"
));
}
@Test
@DisplayName
(
"addExpense method throws exception when it should"
)
void
addExpenseThrows
(){
itemOverview
.
addExpense
(
new
Expense
(
"description"
,
59.9f
,
false
,
ExpenseCategory
.
BOOKS
,
"03.03.23"
));
itemOverview
.
addExpense
(
new
Expense
(
"description"
,
59.9f
,
false
,
ExpenseCategory
.
BOOKS
,
"03.03.23"
));
}
@Test
@DisplayName
(
"getTotalIncome method gives correct amount"
)
void
getTotalIncomeCorrectAmount
(){
itemOverview
.
addIncome
(
new
Income
(
"description1"
,
59.9f
,
false
,
IncomeCategory
.
SALARY
,
"03.03.23"
));
itemOverview
.
addIncome
(
new
Income
(
"description2"
,
62.4f
,
true
,
IncomeCategory
.
GIFT
,
"01.02.21"
));
itemOverview
.
addIncome
(
new
Income
(
"description3"
,
9.81f
,
false
,
IncomeCategory
.
SALARY
,
"05.07.23"
));
double
totalIncome
=
59.9f
+
62.4f
+
9.81f
;
assertEquals
(
Math
.
round
(
itemOverview
.
getTotalIncome
()),
Math
.
round
(
totalIncome
));
}
@Test
@DisplayName
(
"getTotalExpense method gives correct amount"
)
void
getTotalExpenseCorrectAmount
(){
itemOverview
.
addExpense
(
new
Expense
(
"description1"
,
59.9f
,
false
,
ExpenseCategory
.
BOOKS
,
"03.03.23"
));
itemOverview
.
addExpense
(
new
Expense
(
"description2"
,
78.2f
,
true
,
ExpenseCategory
.
FOOD
,
"03.04.23"
));
itemOverview
.
addExpense
(
new
Expense
(
"description3"
,
103.5f
,
true
,
ExpenseCategory
.
OTHER
,
"07.03.23"
));
double
totalExpense
=
59.9f
+
78.2f
+
103.5f
;
assertEquals
(
Math
.
round
(
itemOverview
.
getTotalExpense
()),
Math
.
round
(
totalExpense
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment