From 594a1eba41ee4ea3a9df1d824a62617045bd5769 Mon Sep 17 00:00:00 2001
From: danieljankowski <daniel.jankowski@rub.de>
Date: Mon, 11 Mar 2019 12:44:30 +0100
Subject: [PATCH] Fixed: check gaussian

---
 Makefile         |  3 +++
 gaussian.go      | 25 ++++++++++++++++---------
 gaussian_test.go |  5 +++--
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index ac22a50..b71b42e 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,9 @@ test:
 		$(GOTEST) -v -short -covermode=count $(TEST_FILES)
 		$(GOLINT) -set_exit_status $(TEST_FILES)
 		CC=clang $(GOTEST) -v -msan -short $(TEST_FILES)
+test-coverage:
+		$(GOTEST) -v -count=1 -short -covermode=count -coverprofile report/cover.out $(TEST_FILES)
+		$(GOCMD) tool cover -html=report/cover.out -o report/cover.html
 clean: 
 		$(GOCLEAN)
 		rm -f $(BINARY_PATH)$(BINARY_NAME)
diff --git a/gaussian.go b/gaussian.go
index 609a779..ede9b6b 100644
--- a/gaussian.go
+++ b/gaussian.go
@@ -140,16 +140,23 @@ func (f *F2) partialDiagonalize(startRow, startCol, stopRow, stopCol int) {
 func (f *F2) CheckGaussian(startRow, startCol, n int) bool {
 	counter := 0
 
+	// create the bitmask for the bits to check
+	bitmask := big.NewInt(0).SetBit(
+		big.NewInt(0),
+		n,
+		1,
+	)
+
+	bitmask = bitmask.Sub(bitmask, big.NewInt(1))
+	bitmask = bitmask.Lsh(bitmask, uint(startCol))
+
 	// iterate through the rows
-	for _, row := range f.Rows[startRow:] {
-		// if the counter is reached...
-		if counter == n {
-			// ...break
-			break
-		}
+	for i := startRow; i < startRow+n; i++ {
+		// get the row
+		row := f.Rows[i]
 
-		// create the bitmask for the row
-		bitmask := big.NewInt(0).SetBit(
+		// calculate the expected result if it is in echelon form
+		expectedBits := big.NewInt(0).SetBit(
 			big.NewInt(0),
 			startCol+counter,
 			1,
@@ -164,7 +171,7 @@ func (f *F2) CheckGaussian(startRow, startCol, n int) bool {
 		// xor the bits to check with the bitmask
 		shouldBeZero := big.NewInt(0).Xor(
 			bitsToCheck,
-			bitmask,
+			expectedBits,
 		)
 
 		// if the xor'ed result is not zero...
diff --git a/gaussian_test.go b/gaussian_test.go
index 80dcc38..e688a67 100644
--- a/gaussian_test.go
+++ b/gaussian_test.go
@@ -115,8 +115,8 @@ func TestCheckGaussian(t *testing.T) {
 		{
 			description: "3x3 matrix",
 			matrix: NewF2(3, 3).Set([]*big.Int{
+				big.NewInt(3),
 				big.NewInt(2),
-				big.NewInt(1),
 				big.NewInt(4),
 			}),
 			startRow:       0,
@@ -133,7 +133,7 @@ func TestCheckGaussian(t *testing.T) {
 			}),
 			startRow:       1,
 			startCol:       1,
-			n:              3,
+			n:              2,
 			expectedResult: true,
 		},
 		{
@@ -151,6 +151,7 @@ func TestCheckGaussian(t *testing.T) {
 	}
 
 	for _, test := range tests {
+		test.matrix.PrettyPrint()
 		result := test.matrix.CheckGaussian(
 			test.startRow,
 			test.startCol,
-- 
GitLab