forked from cp-algorithms/cp-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gauss.cpp
More file actions
49 lines (42 loc) · 865 Bytes
/
test_gauss.cpp
File metadata and controls
49 lines (42 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
#include "gauss.h"
typedef double dbl;
typedef vector<vector<dbl> > matrix;
typedef vector<dbl> vec;
void test1(){
//x + y = 0
matrix A = {{1, 1}};
vec b = {0};
vec ans(2);
A[0].push_back(b[0]);
assert(gauss(A, ans) == INF);
}
void test2(){
//x + y = 0
//2x + 3y = 1
matrix A = {{1, 1}, {2, 3}};
vec b = {0, 1};
vec ans(2);
A[0].push_back(b[0]);
A[1].push_back(b[1]);
assert(gauss(A, ans) == 1);
assert(abs(ans[0] + 1) < EPS && abs(ans[1] - 1) < EPS);
}
void test3(){
//x = 0
//y = 1
//x + y = 2
matrix A = {{1, 0}, {0, 1}, {1, 1}};
vec b = {0, 1, 2};
vec ans(2);
A[0].push_back(b[0]);
A[1].push_back(b[1]);
A[2].push_back(b[2]);
assert(gauss(A, ans) == 0);
}
int main(){
test1();
test2();
test3();
}