Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<time.h>
- #include<string>
- #include"complex.h"
- #include"polynomial.h"
- using namespace std;
- void test1();
- void test2();
- void test3();
- int main(){
- clock_t start_t = clock();
- test3();
- cout << "execution in " << clock() - start_t << " ms \n";
- getchar();
- return 0;
- }
- void test1(){
- cout << "--------------------" << endl;
- cout << "TEST 1" << endl;
- monomial* a = new monomial(1, 2);
- monomial* b = new monomial(2, 1);
- monomial* c = new monomial(3, 0);
- monomial* d = new monomial(*b);
- polynomial* p = new polynomial;
- *p += *a;
- *p += *b;
- *p += *c;
- *p += *d;
- cout << "a: " << *a << endl;
- cout << "b: " << *b << endl;
- cout << "c: " << *c << endl;
- cout << "p: " << *p << endl;
- delete p;delete a;delete b;delete c;delete d;
- }
- void test2(){
- cout << endl;
- cout << "--------------------" << endl;
- cout << "TEST 2" << endl;
- double** t = new double*[3];
- t[0] = new double[2]; t[0][0] = 1; t[0][1] = 2;
- t[1] = new double[2]; t[1][0] = 2; t[1][1] = 1;
- t[2] = new double[2]; t[2][0] = 3; t[2][1] = 0;
- polynomial *p = new polynomial(t, 3);
- t[0][0] = 5; t[0][1] = 3;
- t[1][0] = 6; t[1][1] = 2;
- t[2][0] = 7; t[2][1] = 1;
- polynomial *q = new polynomial(t, 3);
- p->sort(); q->sort();
- polynomial *a = *p + *q;
- polynomial *b = *p - *q;
- polynomial *c = *p * *q;
- polynomial *d = p->mul(*q);
- cout << "p: " << *p << endl;
- cout << "q: " << *q << endl;
- cout << "a: " << *a << endl;
- cout << "b: " << *b << endl;
- cout << "c: " << *c << endl;
- cout << "d: " << *d << endl;
- //delete a,b,c,p,q;
- delete t[0], t[1], t[2], t;
- delete p; cout << "del p" << endl;
- delete q; cout << "del q" << endl;
- delete a; cout << "del a" << endl;
- delete b; cout << "del b" << endl;
- delete c; cout << "del c" << endl;
- delete d; cout << "del d" << endl;
- }
- void test3(){
- cout << endl;
- cout << "--------------------" << endl;
- cout << "TEST 3" << endl;
- polynomial* p = polynomial::rand(300)->simplify();
- polynomial* q = polynomial::rand(300)->simplify();
- //cout << "p: " << *p << endl;
- //cout << "q: " << *q << endl;
- clock_t vst;
- vst = clock(); polynomial::dt = 0;
- polynomial* pq1 = *p * *q;
- cout << "naive mul time " << clock() - vst << " ms \n";//
- //cout << "pq1: " << *pq1 << " \n";
- cout << "pq1 size: " << pq1->size() << endl;
- cout << "pq1 ssize: " << pq1->simplify()->size() << endl;
- cout << "evaluate on x=1/2: " << pq1->eval(0.5) << endl;
- cout << "deletion time: " << polynomial::dt << endl;
- delete pq1;
- vst = clock(); polynomial::dt = 0; polynomial::steps = 0;
- polynomial* pq2 = (*p).mul(*q);
- cout << "divide and conquer mul time " << clock() - vst << " ms \n";
- //cout << "pq2: " << *pq2 << " \n";
- cout << "pq2 size: " << pq2->size() << endl;
- cout << "pq2 ssize: " << pq2->simplify()->size() << endl;
- cout << "evaluate on x=1/2: " << pq2->eval(0.5) << endl;
- cout << "deletion time: " << polynomial::dt << endl;
- delete pq2;
- delete p;
- delete q;
- }
Advertisement
Add Comment
Please, Sign In to add comment