Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
3c154f08
Commit
3c154f08
authored
5 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for SparseMatrixDescriptor
parent
ac04676b
No related branches found
No related tags found
1 merge request
!26
Feature/linear systems
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/CMakeLists.txt
tests/test_SparseMatrixDescriptor.cpp
+168
-0
168 additions, 0 deletions
tests/test_SparseMatrixDescriptor.cpp
with
169 additions
and
0 deletions
tests/CMakeLists.txt
+
1
−
0
View file @
3c154f08
...
@@ -8,6 +8,7 @@ add_executable (unit_tests
...
@@ -8,6 +8,7 @@ add_executable (unit_tests
test_ItemType.cpp
test_ItemType.cpp
test_PugsAssert.cpp
test_PugsAssert.cpp
test_RevisionInfo.cpp
test_RevisionInfo.cpp
test_SparseMatrixDescriptor.cpp
test_TinyMatrix.cpp
test_TinyMatrix.cpp
test_TinyVector.cpp
test_TinyVector.cpp
test_Vector.cpp
test_Vector.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/test_SparseMatrixDescriptor.cpp
0 → 100644
+
168
−
0
View file @
3c154f08
#include
<catch2/catch.hpp>
#include
<PugsAssert.hpp>
#include
<SparseMatrixDescriptor.hpp>
// Instantiate to ensure full coverage is performed
template
class
SparseMatrixDescriptor
<
int
,
uint8_t
>;
TEST_CASE
(
"SparseMatrixDescriptor"
,
"[algebra]"
)
{
SECTION
(
"SparseRowDescriptor subclass"
)
{
SECTION
(
"number of values"
)
{
SparseMatrixDescriptor
<
int
,
uint8_t
>::
SparseRowDescriptor
r
;
REQUIRE
(
r
.
numberOfValues
()
==
0
);
r
[
0
]
=
3
;
r
[
0
]
+=
2
;
REQUIRE
(
r
.
numberOfValues
()
==
1
);
r
[
1
]
=
-
2
;
REQUIRE
(
r
.
numberOfValues
()
==
2
);
}
SECTION
(
"values access"
)
{
SparseMatrixDescriptor
<
int
,
uint8_t
>::
SparseRowDescriptor
r
;
r
[
0
]
=
3
;
r
[
0
]
+=
2
;
r
[
3
]
=
8
;
REQUIRE
(
r
[
0
]
==
5
);
REQUIRE
(
r
[
3
]
==
8
);
const
auto
&
const_r
=
r
;
REQUIRE
(
const_r
[
0
]
==
5
);
REQUIRE
(
const_r
[
3
]
==
8
);
#ifndef NDEBUG
REQUIRE_THROWS_AS
(
const_r
[
2
],
AssertError
);
#endif // NDEBUG
}
}
SECTION
(
"number of columns"
)
{
SparseMatrixDescriptor
<
int
,
uint8_t
>
S
{
5
};
REQUIRE
(
S
.
numberOfRows
()
==
5
);
}
SECTION
(
"location operators"
)
{
SparseMatrixDescriptor
<
int
,
uint8_t
>
S
{
5
};
S
(
0
,
2
)
=
3
;
S
(
1
,
1
)
=
1
;
S
(
1
,
2
)
=
11
;
S
(
0
,
2
)
+=
2
;
S
(
2
,
2
)
=
4
;
S
(
3
,
1
)
=
5
;
S
(
4
,
1
)
=
1
;
S
(
4
,
4
)
=
-
2
;
REQUIRE
(
S
.
row
(
0
).
numberOfValues
()
==
1
);
REQUIRE
(
S
.
row
(
1
).
numberOfValues
()
==
2
);
REQUIRE
(
S
.
row
(
2
).
numberOfValues
()
==
1
);
REQUIRE
(
S
.
row
(
3
).
numberOfValues
()
==
1
);
REQUIRE
(
S
.
row
(
4
).
numberOfValues
()
==
2
);
const
auto
&
const_S
=
S
;
REQUIRE
(
const_S
.
row
(
0
).
numberOfValues
()
==
1
);
REQUIRE
(
const_S
.
row
(
1
).
numberOfValues
()
==
2
);
REQUIRE
(
const_S
.
row
(
2
).
numberOfValues
()
==
1
);
REQUIRE
(
const_S
.
row
(
3
).
numberOfValues
()
==
1
);
REQUIRE
(
const_S
.
row
(
4
).
numberOfValues
()
==
2
);
#ifndef NDEBUG
REQUIRE_THROWS_AS
(
S
.
row
(
5
),
AssertError
);
REQUIRE_THROWS_AS
(
const_S
.
row
(
5
),
AssertError
);
#endif // NDEBUG
REQUIRE
(
S
(
0
,
2
)
==
5
);
REQUIRE
(
S
(
1
,
1
)
==
1
);
REQUIRE
(
S
(
1
,
2
)
==
11
);
REQUIRE
(
S
(
2
,
2
)
==
4
);
REQUIRE
(
S
(
3
,
1
)
==
5
);
REQUIRE
(
S
(
4
,
1
)
==
1
);
REQUIRE
(
S
(
4
,
4
)
==
-
2
);
REQUIRE
(
const_S
(
0
,
2
)
==
5
);
REQUIRE
(
const_S
(
1
,
1
)
==
1
);
REQUIRE
(
const_S
(
1
,
2
)
==
11
);
REQUIRE
(
const_S
(
2
,
2
)
==
4
);
REQUIRE
(
const_S
(
3
,
1
)
==
5
);
REQUIRE
(
const_S
(
4
,
1
)
==
1
);
REQUIRE
(
const_S
(
4
,
4
)
==
-
2
);
#ifndef NDEBUG
REQUIRE_THROWS_AS
(
S
(
5
,
0
),
AssertError
);
REQUIRE_THROWS_AS
(
const_S
(
6
,
1
),
AssertError
);
REQUIRE_THROWS_AS
(
const_S
(
0
,
1
),
AssertError
);
#endif // NDEBUG
}
SECTION
(
"vector-graph"
)
{
SparseMatrixDescriptor
<
int
,
uint8_t
>
S
{
5
};
S
(
0
,
2
)
=
3
;
S
(
1
,
2
)
=
11
;
S
(
1
,
1
)
=
1
;
S
(
0
,
2
)
+=
2
;
S
(
3
,
3
)
=
5
;
S
(
3
,
1
)
=
5
;
S
(
4
,
1
)
=
1
;
S
(
2
,
2
)
=
4
;
S
(
4
,
4
)
=
-
2
;
const
auto
graph
=
S
.
graphVector
();
REQUIRE
(
graph
.
size
()
==
S
.
numberOfRows
());
REQUIRE
(
graph
[
0
].
size
()
==
1
);
REQUIRE
(
graph
[
1
].
size
()
==
2
);
REQUIRE
(
graph
[
2
].
size
()
==
1
);
REQUIRE
(
graph
[
3
].
size
()
==
2
);
REQUIRE
(
graph
[
4
].
size
()
==
2
);
REQUIRE
(
graph
[
0
][
0
]
==
2
);
REQUIRE
(
graph
[
1
][
0
]
==
1
);
REQUIRE
(
graph
[
1
][
1
]
==
2
);
REQUIRE
(
graph
[
2
][
0
]
==
2
);
REQUIRE
(
graph
[
3
][
0
]
==
1
);
REQUIRE
(
graph
[
3
][
1
]
==
3
);
REQUIRE
(
graph
[
4
][
0
]
==
1
);
REQUIRE
(
graph
[
4
][
1
]
==
4
);
}
SECTION
(
"value array"
)
{
SparseMatrixDescriptor
<
int
,
uint8_t
>
S
{
5
};
S
(
0
,
2
)
=
3
;
S
(
1
,
2
)
=
11
;
S
(
1
,
1
)
=
1
;
S
(
0
,
2
)
+=
2
;
S
(
3
,
3
)
=
5
;
S
(
3
,
1
)
=
-
3
;
S
(
4
,
1
)
=
1
;
S
(
2
,
2
)
=
4
;
S
(
4
,
4
)
=
-
2
;
const
auto
value_array
=
S
.
valueArray
();
REQUIRE
(
value_array
.
size
()
==
8
);
REQUIRE
(
value_array
[
0
]
==
5
);
REQUIRE
(
value_array
[
1
]
==
1
);
REQUIRE
(
value_array
[
2
]
==
11
);
REQUIRE
(
value_array
[
3
]
==
4
);
REQUIRE
(
value_array
[
4
]
==
-
3
);
REQUIRE
(
value_array
[
5
]
==
5
);
REQUIRE
(
value_array
[
6
]
==
1
);
REQUIRE
(
value_array
[
7
]
==
-
2
);
}
}
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