Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ unittest_SOURCES=src/test/Range.cpp \
src/test/QuadMatrixBuilder.cpp src/test/F4MatrixBuilder.cpp \
src/test/F4MatrixReducer.cpp src/test/mathicgb.cpp \
src/test/PrimeField.cpp src/test/MonoMonoid.cpp src/test/Scanner.cpp \
src/test/MathicIO.cpp src/test/CFile.cpp
src/test/MathicIO.cpp src/test/CFile.cpp src/test/QuadMatrix.cpp

else

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ if(BUILD_TESTING)
test/MathicIO.cpp
test/MonoMonoid.cpp
test/PrimeField.cpp
test/QuadMatrix.cpp
test/QuadMatrixBuilder.cpp
test/Range.cpp
test/Scanner.cpp
Expand Down
8 changes: 3 additions & 5 deletions src/mathicgb/QuadMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@ SparseMatrix::Scalar QuadMatrix::read(FILE* file) {
rightColumnMonomials.clear();

const auto topLeftModulus = topLeft.read(file);
#ifdef MATHICGB_DEBUG
const auto topRightModulus = topRight.read(file);
const auto bottomLeftModulus = bottomLeft.read(file);
const auto bottomRightModulus = bottomRight.read(file);
#endif
[[maybe_unused]] const auto topRightModulus = topRight.read(file);
[[maybe_unused]] const auto bottomLeftModulus = bottomLeft.read(file);
[[maybe_unused]] const auto bottomRightModulus = bottomRight.read(file);
// todo: this should throw some kind of invalid format exception instead of
// these asserts.
MATHICGB_ASSERT(topLeftModulus == topRightModulus);
Expand Down
44 changes: 44 additions & 0 deletions src/test/QuadMatrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// MathicGB copyright 2012 all rights reserved. MathicGB comes with ABSOLUTELY
// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.
#include "mathicgb/stdinc.h"
#include "mathicgb/QuadMatrix.hpp"

#include "mathicgb/CFile.hpp"
#include <gtest/gtest.h>
#include <cstdio>

using namespace mgb;

TEST(QuadMatrix, ReadWritesAllFourSubmatrices) {
const SparseMatrix::Scalar modulus = 101;

// A distinct entry per quadrant, so that an empty quadrant and a quadrant
// holding another's data both show up.
QuadMatrix in;
in.topLeft.appendEntry(0, 11);
in.topLeft.rowDone();
in.topRight.appendEntry(1, 22);
in.topRight.rowDone();
in.bottomLeft.appendEntry(2, 33);
in.bottomLeft.rowDone();
in.bottomRight.appendEntry(3, 44);
in.bottomRight.rowDone();

const char* const fileName = "QuadMatrix-test.tmp";
{
CFile file(fileName, "wb");
in.write(modulus, file.handle());
}

QuadMatrix out;
{
CFile file(fileName, "rb");
ASSERT_EQ(modulus, out.read(file.handle()));
}
ASSERT_EQ(0, std::remove(fileName));

ASSERT_EQ(in.topLeft.toString(), out.topLeft.toString());
ASSERT_EQ(in.topRight.toString(), out.topRight.toString());
ASSERT_EQ(in.bottomLeft.toString(), out.bottomLeft.toString());
ASSERT_EQ(in.bottomRight.toString(), out.bottomRight.toString());
}
Loading