Main.cpp 2.35 KB
Newer Older
Hernandez Francois's avatar
Hernandez Francois committed
1 2 3 4 5 6 7
// Main.cpp

#include <iostream>
#include <iomanip>

#include "Derivation.hpp"

Hernandez Francois's avatar
Hernandez Francois committed
8 9
using namespace std;

Hernandez Francois's avatar
Hernandez Francois committed
10 11
int main()
{
Hernandez Francois's avatar
Hernandez Francois committed
12 13
	Nombre * zero = new Nombre(0);
	std::cout << zero->nb_instances() << std::endl;
Hernandez Francois's avatar
Hernandez Francois committed
14 15 16 17 18

	Nombre * un = new Nombre(1);
	Nombre * deux = new Nombre(2);
	Nombre * trois = new Nombre(3);

Hernandez Francois's avatar
Hernandez Francois committed
19
	std::cout << zero->nb_instances() << std::endl;
Hernandez Francois's avatar
Hernandez Francois committed
20 21 22 23

	Variable * x = new Variable('x');
	Variable * y = new Variable('y');

Hernandez Francois's avatar
Hernandez Francois committed
24 25
	std::cout << zero->nb_instances() << std::endl;

Hernandez Francois's avatar
Hernandez Francois committed
26
	Plus * unpx = new Plus(un, x);
Hernandez Francois's avatar
Hernandez Francois committed
27
	std::cout << zero->nb_instances() << std::endl;
Hernandez Francois's avatar
Hernandez Francois committed
28
	Diviser * xsury = new Diviser(x,y);
Hernandez Francois's avatar
Hernandez Francois committed
29
	std::cout << zero->nb_instances() << std::endl;
Hernandez Francois's avatar
Hernandez Francois committed
30 31
	Multiplier * test = new Multiplier(unpx,xsury);

Hernandez Francois's avatar
Hernandez Francois committed
32 33
	std::cout << zero->nb_instances() << std::endl;

Hernandez Francois's avatar
Hernandez Francois committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	std::cout << "Expression à dériver : " << std::endl;
	std::cout << *test << std::endl;

	Expression * testx = test->derive('x');
	Expression * testy = test->derive('y');
	Expression * testxs = testx->simplifie();
	Expression * testys = testy->simplifie();

	std::cout << "Dérivée par rapport à x : " << std::endl;
	std::cout << *testx << std::endl;
	std::cout << "Simplification : " << std::endl;
	std::cout << *testxs << std::endl;

	std::cout << "Dérivée par rapport à y : " << std::endl;
	std::cout << *testy << std::endl;
	std::cout << "Simplification : " << std::endl;
	std::cout << *testys << std::endl;

Hernandez Francois's avatar
Hernandez Francois committed
52 53
	//Diviser * divzero = new Diviser(un, zero);
	//std::cout << *divzero << std::endl;
Hernandez Francois's avatar
Hernandez Francois committed
54

Hernandez Francois's avatar
Hernandez Francois committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	delete testys;
	delete testy;
	delete testxs;
	delete testx;
	delete test;
	delete unpx;
	delete xsury;
	delete x;
	delete y;
	delete zero;
	delete un;
	delete deux;
	delete trois;

	/* TEST INSTANCES

	Nombre * un = new Nombre(1);
	Nombre * deux = new Nombre(2);
	Variable * x = new Variable('x');

	std::cout << Expression::nb_instances()<<std::endl;

	Diviser * p = new Diviser(deux,x);

	std::cout << Expression::nb_instances()<<std::endl;

	Expression * d = p->derive('x');

	std::cout << *d << std::endl;

	std::cout << Expression::nb_instances()<<std::endl;

	Expression * s = d->simplifie();

	std::cout << Expression::nb_instances()<<std::endl;

	delete s;

	std::cout << Expression::nb_instances()<<std::endl;

	delete d;

	std::cout << Expression::nb_instances()<<std::endl;

	delete p;

	std::cout << Expression::nb_instances()<<std::endl;

	delete un;
	delete deux;
	delete x;

	*/

	std::cout << Expression::nb_instances()<<std::endl;

	return 0;
Hernandez Francois's avatar
Hernandez Francois committed
112

113

Hernandez Francois's avatar
Hernandez Francois committed
114
}