Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fip112-2025-g41
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
BINTI TENGKU MASRULHISHAM Tengku Maryam Naqeesha
fip112-2025-g41
Commits
13388cf0
Commit
13388cf0
authored
1 month ago
by
MASSY FERNANDEZ Neva Aracely
Browse files
Options
Downloads
Patches
Plain Diff
add: ConsultItemBookTest
parent
26efaacb
No related branches found
No related tags found
1 merge request
!7
Merge code for iteration3 with main
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tests/ConsultItemBookTest.java
+61
-1
61 additions, 1 deletion
src/tests/ConsultItemBookTest.java
src/tests/ReviewItemBookTest.java
+5
-5
5 additions, 5 deletions
src/tests/ReviewItemBookTest.java
with
66 additions
and
6 deletions
src/tests/ConsultItemBookTest.java
+
61
−
1
View file @
13388cf0
package
tests
;
import
opinion.SocialNetwork
;
import
opinion.ISocialNetwork
;
import
exceptions.BadEntryException
;
import
exceptions.ItemBookAlreadyExistsException
;
import
exceptions.MemberAlreadyExistsException
;
import
exceptions.NotMemberException
;
import
java.util.LinkedList
;
public
class
ConsultItemBookTest
{
private
static
int
nbTests
=
0
;
private
static
int
nbErrors
=
0
;
private
static
void
displaySuccess
(
String
message
)
{
System
.
out
.
println
(
"Test passed: "
+
message
);
}
...
...
@@ -12,8 +22,58 @@ public class ConsultItemBookTest {
System
.
out
.
println
(
"Test failed: "
+
message
);
nbErrors
++;
}
public
static
void
testConsultItemBook
()
{
private
static
void
testExpectedException
(
ISocialNetwork
sn
,
String
title
,
Class
<?>
expectedException
,
String
testId
)
{
nbTests
++;
try
{
sn
.
consultItems
(
title
);
displayError
(
"["
+
testId
+
"] Expected exception "
+
expectedException
.
getSimpleName
()
+
" but none was thrown"
);
}
catch
(
Exception
e
)
{
if
(
e
.
getClass
().
equals
(
expectedException
))
{
displaySuccess
(
"["
+
testId
+
"] Correctly threw "
+
expectedException
.
getSimpleName
());
}
else
{
displayError
(
"["
+
testId
+
"] Unexpected exception: "
+
e
);
}
}
}
private
static
void
testConsultResult
(
ISocialNetwork
sn
,
String
title
,
int
expectedSize
,
String
testId
)
{
nbTests
++;
try
{
LinkedList
<
String
>
results
=
sn
.
consultItems
(
title
);
if
(
results
.
size
()
==
expectedSize
)
{
displaySuccess
(
"["
+
testId
+
"] Returned expected number of results: "
+
expectedSize
);
}
else
{
displayError
(
"["
+
testId
+
"] Expected "
+
expectedSize
+
" but got "
+
results
.
size
());
}
}
catch
(
Exception
e
)
{
displayError
(
"["
+
testId
+
"] Unexpected exception: "
+
e
);
}
}
public
static
void
main
(
String
[]
args
)
{
ISocialNetwork
sn
=
new
SocialNetwork
();
try
{
sn
.
addMember
(
"user1"
,
"pass1234"
,
"profile"
);
sn
.
addItemBook
(
"user1"
,
"pass1234"
,
"Don Quijote"
,
"Novela"
,
"Cervantes"
,
800
);
sn
.
addItemBook
(
"user1"
,
"pass1234"
,
"El Principito"
,
"Fábula"
,
"Saint-Exupéry"
,
100
);
sn
.
addItemBook
(
"user1"
,
"pass1234"
,
"Principios de Física"
,
"Ciencia"
,
"Tipler"
,
1200
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Setup failed: "
+
e
);
return
;
}
// Exception cases
testExpectedException
(
sn
,
null
,
BadEntryException
.
class
,
"3.8"
);
testExpectedException
(
sn
,
" "
,
BadEntryException
.
class
,
"3.9"
);
testExpectedException
(
sn
,
"a"
,
BadEntryException
.
class
,
"3.10"
);
// Success cases
testConsultResult
(
sn
,
"princip"
,
2
,
"3.11"
);
// It returns two books "El principito" and "Principios de la fisica"
testConsultResult
(
sn
,
"DON"
,
1
,
"3.12"
);
// test case-sensitive
testConsultResult
(
sn
,
"XYZ"
,
0
,
"3.13"
);
// no results
System
.
out
.
println
(
"\nConsultItemBookTest: "
+
nbTests
+
" tests run, "
+
nbErrors
+
" errors."
);
}
}
This diff is collapsed.
Click to expand it.
src/tests/ReviewItemBookTest.java
+
5
−
5
View file @
13388cf0
...
...
@@ -60,12 +60,12 @@ public class ReviewItemBookTest {
return
null
;
}
// ---
Casos exitoso
s ---
testExpectedAverage
(
sn
,
"ana"
,
"pass123"
,
"El Hobbit"
,
4.0f
,
"
Muy bueno
"
,
4.0f
,
"1.1"
);
testExpectedAverage
(
sn
,
"luis"
,
"1234pass"
,
"El Hobbit"
,
5.0f
,
"
Obra maestra
"
,
4.5f
,
"1.2"
);
testExpectedAverage
(
sn
,
"ana"
,
"pass123"
,
"El Hobbit"
,
3.0f
,
"
Bueno pero largo
"
,
4.0f
,
"1.3"
);
// ---
Sucess case
s ---
testExpectedAverage
(
sn
,
"ana"
,
"pass123"
,
"El Hobbit"
,
4.0f
,
"
So good
"
,
4.0f
,
"1.1"
);
testExpectedAverage
(
sn
,
"luis"
,
"1234pass"
,
"El Hobbit"
,
5.0f
,
"
excelent!
"
,
4.5f
,
"1.2"
);
testExpectedAverage
(
sn
,
"ana"
,
"pass123"
,
"El Hobbit"
,
3.0f
,
"
good but long
"
,
4.0f
,
"1.3"
);
// --- Cas
o
s
de error esperados
---
// --- Cas
e
s
with exception
---
testExpectedException
(
sn
,
"mario"
,
"nopass"
,
"El Hobbit"
,
4.0f
,
"Hola"
,
NotMemberException
.
class
,
"3.1"
);
testExpectedException
(
sn
,
"ana"
,
"pass123"
,
"Book X"
,
3.0f
,
"Does not exist"
,
NotItemException
.
class
,
"3.2"
);
testExpectedException
(
sn
,
"ana"
,
"pass123"
,
"El Hobbit"
,
6.0f
,
"Out of range"
,
BadEntryException
.
class
,
"3.3"
);
...
...
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