Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
algodat-sose21-tests
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
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Nikolaus Supper
algodat-sose21-tests
Commits
3dfca13d
Commit
3dfca13d
authored
3 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
contrast
parent
6885231c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Blatt08/src/MatrixImageTest.java
+115
-0
115 additions, 0 deletions
Blatt08/src/MatrixImageTest.java
with
115 additions
and
0 deletions
Blatt08/src/MatrixImageTest.java
0 → 100644
+
115
−
0
View file @
3dfca13d
import
java.util.InputMismatchException
;
import
java.util.Random
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
MatrixImageTest
{
@org
.
junit
.
jupiter
.
api
.
Test
void
removeVPath1
()
throws
java
.
io
.
FileNotFoundException
{
int
[]
path
=
{
0
,
0
};
int
[][]
matrixB
=
{{
1
,
3
},
{
2
,
4
}};
int
[][]
matrixA
=
{{
2
,
4
}};
processRemoveTest
(
matrixA
,
matrixB
,
path
,
2
,
2
);
}
@org
.
junit
.
jupiter
.
api
.
Test
void
removeVPath2
()
throws
java
.
io
.
FileNotFoundException
{
int
[]
path
=
{
0
,
0
,
0
};
int
[][]
matrixB
=
{{
1
,
4
,
7
},
{
2
,
5
,
8
},
{
3
,
6
,
9
}};
int
[][]
matrixA
=
{{
2
,
5
,
8
},
{
3
,
6
,
9
}};
processRemoveTest
(
matrixA
,
matrixB
,
path
,
3
,
3
);
}
@org
.
junit
.
jupiter
.
api
.
Test
void
removeVPath3
()
throws
java
.
io
.
FileNotFoundException
{
int
[]
path
=
{
1
,
1
,
1
};
int
[][]
matrixB
=
{{
1
,
3
,
5
},
{
2
,
4
,
6
}};
int
[][]
matrixA
=
{{
1
,
3
,
5
}};
processRemoveTest
(
matrixA
,
matrixB
,
path
,
2
,
3
);
}
@org
.
junit
.
jupiter
.
api
.
Test
void
removeVPath4
()
throws
java
.
io
.
FileNotFoundException
{
int
[]
path
=
{
1
,
2
};
int
[][]
matrixB
=
{{
1
,
4
},
{
2
,
5
},
{
3
,
6
}};
int
[][]
matrixA
=
{{
1
,
4
},
{
3
,
5
}};
processRemoveTest
(
matrixA
,
matrixB
,
path
,
3
,
2
);
}
void
processRemoveTest
(
int
[][]
matrixA
,
int
[][]
matrixB
,
int
[]
path
,
int
x
,
int
y
)
{
MatrixImage
matrixImage
=
new
MatrixImage
(
x
,
y
);
matrixImage
.
field
=
matrixB
;
matrixImage
.
removeVPath
(
path
);
matrixB
=
matrixImage
.
field
;
areMatrixIdentical
(
matrixA
,
matrixB
);
}
void
areMatrixIdentical
(
int
[][]
matrixA
,
int
[][]
matrixB
)
{
assertNotNull
(
matrixA
,
"Null Pointer zurückgegeben"
);
assertNotNull
(
matrixB
,
"Null Pointer zurückgegeben"
);
assertEquals
(
matrixA
.
length
,
matrixB
.
length
,
"Größe der Matrix stimmt nicht"
);
assertEquals
(
matrixA
[
0
].
length
,
matrixB
[
0
].
length
,
"Größe der Matrix stimmt nicht"
);
for
(
int
i
=
0
;
i
<
matrixA
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
matrixA
[
0
].
length
;
j
++)
{
assertEquals
(
matrixA
[
i
][
j
],
matrixB
[
i
][
j
],
"Falscher Wert an ["
+
i
+
"]["
+
j
+
"]"
);
}
}
}
@org
.
junit
.
jupiter
.
api
.
Test
void
contrastCheckExceptions
()
throws
java
.
io
.
FileNotFoundException
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
Random
r
=
new
Random
();
int
x
=
r
.
nextInt
(
9
)
+
1
;
int
y
=
r
.
nextInt
(
9
)
+
1
;
MatrixImage
matrixImage
=
new
MatrixImage
(
x
,
y
);
assertThrows
(
InputMismatchException
.
class
,
()
->
{
matrixImage
.
contrast
(
new
Coordinate
(
x
-
1
,
y
-
1
),
new
Coordinate
(
x
-
1
,
y
));
},
"wirft keine exception"
);
assertThrows
(
InputMismatchException
.
class
,
()
->
{
matrixImage
.
contrast
(
new
Coordinate
(
x
,
y
-
1
),
new
Coordinate
(
x
-
1
,
y
-
1
));
},
"wirft keine exception"
);
assertThrows
(
InputMismatchException
.
class
,
()
->
{
matrixImage
.
contrast
(
new
Coordinate
(
x
-
1
,
y
-
1
),
new
Coordinate
(
x
-
1
,
-
1
));
},
"wirft keine exception"
);
assertThrows
(
InputMismatchException
.
class
,
()
->
{
matrixImage
.
contrast
(
new
Coordinate
(-
1
,
y
-
1
),
new
Coordinate
(
x
-
1
,
y
-
1
));
},
"wirft keine exception"
);
assertDoesNotThrow
(()
->
matrixImage
.
contrast
(
new
Coordinate
(
x
-
1
,
y
-
1
),
new
Coordinate
(
0
,
0
)),
"Wirft exception, obwohl index in der matrix liegen sollte"
);
}
}
@org
.
junit
.
jupiter
.
api
.
Test
void
contrast1
()
throws
java
.
io
.
FileNotFoundException
{
int
[][]
matrixA
=
{{
1
,
3
},
{
2
,
4
}};
MatrixImage
m
=
new
MatrixImage
(
2
,
2
);
m
.
field
=
matrixA
;
assertEquals
(
0.0
,
m
.
contrast
(
new
Coordinate
(
1
,
1
),
new
Coordinate
(
1
,
1
)));
assertTrue
(
m
.
contrast
(
new
Coordinate
(
1
,
0
),
new
Coordinate
(
0
,
1
))
>=
0
,
""
+
"contrast should only return positive values"
);
assertEquals
(
1.0
,
m
.
contrast
(
new
Coordinate
(
1
,
0
),
new
Coordinate
(
0
,
1
)));
assertTrue
(
m
.
contrast
(
new
Coordinate
(
1
,
1
),
new
Coordinate
(
0
,
0
))
>=
0
,
""
+
"contrast should only return positive values"
);
assertEquals
(
3.0
,
m
.
contrast
(
new
Coordinate
(
1
,
1
),
new
Coordinate
(
0
,
0
)));
}
@org
.
junit
.
jupiter
.
api
.
Test
void
contrast2
()
throws
java
.
io
.
FileNotFoundException
{
int
[][]
matrix
=
{{
5
,
4
,
3
,
2
,
1
}};
MatrixImage
m
=
new
MatrixImage
(
1
,
5
);
m
.
field
=
matrix
;
assertEquals
(
0
,
m
.
contrast
(
new
Coordinate
(
0
,
4
),
new
Coordinate
(
0
,
4
)));
assertTrue
(
m
.
contrast
(
new
Coordinate
(
0
,
2
),
new
Coordinate
(
0
,
3
))
>=
0
,
""
+
"contrast should only return positive values"
);
assertEquals
(
1.0
,
m
.
contrast
(
new
Coordinate
(
0
,
2
),
new
Coordinate
(
0
,
1
)));
assertTrue
(
m
.
contrast
(
new
Coordinate
(
0
,
3
),
new
Coordinate
(
0
,
4
))
>=
0
,
""
+
"contrast should only return positive values"
);
assertEquals
(
1.0
,
m
.
contrast
(
new
Coordinate
(
0
,
3
),
new
Coordinate
(
0
,
4
)));
}
}
\ No newline at end of file
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