From 8f1093f0e00f9b1df7ce343a879303fd56a95d08 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Tue, 29 Oct 2013 17:42:34 +0100 Subject: First commit. --- tests/exec/ABR.cpp | 60 ++++++++++++++++++++++++++ tests/exec/ABR.out | 3 ++ tests/exec/Makefile | 6 +++ tests/exec/address1.cpp | 11 +++++ tests/exec/address1.out | 3 ++ tests/exec/address2.cpp | 12 ++++++ tests/exec/address2.out | 2 + tests/exec/address3.cpp | 14 ++++++ tests/exec/address3.out | 3 ++ tests/exec/affect.cpp | 12 ++++++ tests/exec/affect.out | 2 + tests/exec/arith1.cpp | 14 ++++++ tests/exec/arith1.out | 5 +++ tests/exec/bst.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++ tests/exec/bst.out | 4 ++ tests/exec/for1.cpp | 7 +++ tests/exec/for1.out | 10 +++++ tests/exec/for2.cpp | 8 ++++ tests/exec/for2.out | 11 +++++ tests/exec/for3.cpp | 11 +++++ tests/exec/for3.out | 27 ++++++++++++ tests/exec/global.cpp | 14 ++++++ tests/exec/global.out | 3 ++ tests/exec/hexa.cpp | 15 +++++++ tests/exec/hexa.out | 7 +++ tests/exec/inheritance1.cpp | 30 +++++++++++++ tests/exec/inheritance1.out | 4 ++ tests/exec/inheritance2.cpp | 26 ++++++++++++ tests/exec/inheritance2.out | 2 + tests/exec/josephus.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++++ tests/exec/josephus.out | 6 +++ tests/exec/mandelbrot.cpp | 60 ++++++++++++++++++++++++++ tests/exec/mandelbrot.out | 30 +++++++++++++ tests/exec/octal.cpp | 13 ++++++ tests/exec/octal.out | 6 +++ tests/exec/pascal.cpp | 62 +++++++++++++++++++++++++++ tests/exec/pascal.out | 42 ++++++++++++++++++ tests/exec/passing.cpp | 13 ++++++ tests/exec/passing.out | 2 + tests/exec/prepost1.cpp | 14 ++++++ tests/exec/prepost1.out | 5 +++ tests/exec/ref1.cpp | 8 ++++ tests/exec/ref1.out | 1 + tests/exec/ref2.cpp | 14 ++++++ tests/exec/ref2.out | 3 ++ tests/exec/ref3.cpp | 18 ++++++++ tests/exec/ref3.out | 5 +++ tests/exec/ref4.cpp | 16 +++++++ tests/exec/ref4.out | 4 ++ tests/exec/ref5.cpp | 29 +++++++++++++ tests/exec/ref5.out | 13 ++++++ tests/exec/ref6.cpp | 20 +++++++++ tests/exec/ref6.out | 8 ++++ tests/exec/string.cpp | 10 +++++ tests/exec/string.out | 7 +++ tests/exec/true_false.cpp | 8 ++++ tests/exec/true_false.out | 2 + tests/exec/vehicles.cpp | 78 ++++++++++++++++++++++++++++++++++ tests/exec/vehicles.out | 10 +++++ 59 files changed, 1035 insertions(+) create mode 100644 tests/exec/ABR.cpp create mode 100644 tests/exec/ABR.out create mode 100644 tests/exec/Makefile create mode 100644 tests/exec/address1.cpp create mode 100644 tests/exec/address1.out create mode 100644 tests/exec/address2.cpp create mode 100644 tests/exec/address2.out create mode 100644 tests/exec/address3.cpp create mode 100644 tests/exec/address3.out create mode 100644 tests/exec/affect.cpp create mode 100644 tests/exec/affect.out create mode 100644 tests/exec/arith1.cpp create mode 100644 tests/exec/arith1.out create mode 100644 tests/exec/bst.cpp create mode 100644 tests/exec/bst.out create mode 100644 tests/exec/for1.cpp create mode 100644 tests/exec/for1.out create mode 100644 tests/exec/for2.cpp create mode 100644 tests/exec/for2.out create mode 100644 tests/exec/for3.cpp create mode 100644 tests/exec/for3.out create mode 100644 tests/exec/global.cpp create mode 100644 tests/exec/global.out create mode 100644 tests/exec/hexa.cpp create mode 100644 tests/exec/hexa.out create mode 100644 tests/exec/inheritance1.cpp create mode 100644 tests/exec/inheritance1.out create mode 100644 tests/exec/inheritance2.cpp create mode 100644 tests/exec/inheritance2.out create mode 100644 tests/exec/josephus.cpp create mode 100644 tests/exec/josephus.out create mode 100644 tests/exec/mandelbrot.cpp create mode 100644 tests/exec/mandelbrot.out create mode 100644 tests/exec/octal.cpp create mode 100644 tests/exec/octal.out create mode 100644 tests/exec/pascal.cpp create mode 100644 tests/exec/pascal.out create mode 100644 tests/exec/passing.cpp create mode 100644 tests/exec/passing.out create mode 100644 tests/exec/prepost1.cpp create mode 100644 tests/exec/prepost1.out create mode 100644 tests/exec/ref1.cpp create mode 100644 tests/exec/ref1.out create mode 100644 tests/exec/ref2.cpp create mode 100644 tests/exec/ref2.out create mode 100644 tests/exec/ref3.cpp create mode 100644 tests/exec/ref3.out create mode 100644 tests/exec/ref4.cpp create mode 100644 tests/exec/ref4.out create mode 100644 tests/exec/ref5.cpp create mode 100644 tests/exec/ref5.out create mode 100644 tests/exec/ref6.cpp create mode 100644 tests/exec/ref6.out create mode 100644 tests/exec/string.cpp create mode 100644 tests/exec/string.out create mode 100644 tests/exec/true_false.cpp create mode 100644 tests/exec/true_false.out create mode 100644 tests/exec/vehicles.cpp create mode 100644 tests/exec/vehicles.out (limited to 'tests/exec') diff --git a/tests/exec/ABR.cpp b/tests/exec/ABR.cpp new file mode 100644 index 0000000..979ff4b --- /dev/null +++ b/tests/exec/ABR.cpp @@ -0,0 +1,60 @@ +#include + +/* arbres binaires de recherche */ + +class ABR { +public: + int valeur; + ABR *gauche; + ABR *droite; + ABR(ABR *g, int v, ABR *d); + void insere(int x); + int contient(int x); + void affiche(); +}; + +ABR::ABR(ABR *g, int v, ABR *d) { valeur = v; gauche = g; droite = d; } + +void ABR::insere(int x) { + if (x == valeur) return; + if (x < valeur) { + if (gauche == NULL) + gauche = new ABR(NULL, x, NULL); + else + gauche->insere(x); + } else + if (droite == NULL) + droite = new ABR(NULL, x, NULL); + else + droite->insere(x); +} + +int ABR::contient(int x) { + if (x == valeur) return true; + if (x < valeur && gauche != NULL) return gauche->contient(x); + if (droite != NULL) return droite->contient(x); + return false; +} + +void ABR::affiche() { + if (gauche != NULL) gauche->affiche(); + std::cout << "(" << valeur << ")"; + if (droite != NULL) droite->affiche(); +} + + +int main() { + ABR dico = ABR(NULL, 1, NULL); + dico.insere(17); + dico.insere(5); + dico.insere(8); + dico.affiche(); std::cout << "\n"; + + if (dico.contient(5) && + ! dico.contient(0) && + dico.contient(17) && + ! dico.contient(3)) + std::cout << "ok\n"; + + dico.affiche(); std::cout << "\n"; +} diff --git a/tests/exec/ABR.out b/tests/exec/ABR.out new file mode 100644 index 0000000..8855386 --- /dev/null +++ b/tests/exec/ABR.out @@ -0,0 +1,3 @@ +(1)(5)(8)(17) +ok +(1)(5)(8)(17) diff --git a/tests/exec/Makefile b/tests/exec/Makefile new file mode 100644 index 0000000..b260ba0 --- /dev/null +++ b/tests/exec/Makefile @@ -0,0 +1,6 @@ + +%: %.cpp + g++ -o $@ $^ + ./$@ + ./$@ > $*.out + diff --git a/tests/exec/address1.cpp b/tests/exec/address1.cpp new file mode 100644 index 0000000..fe70014 --- /dev/null +++ b/tests/exec/address1.cpp @@ -0,0 +1,11 @@ +#include + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + int *y = &x; + *y = 42; + std::cout << "x = " << x << "\n"; + *y = *y + 1; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/address1.out b/tests/exec/address1.out new file mode 100644 index 0000000..4202a65 --- /dev/null +++ b/tests/exec/address1.out @@ -0,0 +1,3 @@ +x = 41 +x = 42 +x = 43 diff --git a/tests/exec/address2.cpp b/tests/exec/address2.cpp new file mode 100644 index 0000000..75c2c4f --- /dev/null +++ b/tests/exec/address2.cpp @@ -0,0 +1,12 @@ +#include + +void f(int *y) { + *y = 42; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(&x); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/address2.out b/tests/exec/address2.out new file mode 100644 index 0000000..8b53391 --- /dev/null +++ b/tests/exec/address2.out @@ -0,0 +1,2 @@ +x = 41 +x = 42 diff --git a/tests/exec/address3.cpp b/tests/exec/address3.cpp new file mode 100644 index 0000000..3917dc1 --- /dev/null +++ b/tests/exec/address3.cpp @@ -0,0 +1,14 @@ +#include + +void f(int *y) { + *y = *y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(&x); + std::cout << "x = " << x << "\n"; + f(&x); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/address3.out b/tests/exec/address3.out new file mode 100644 index 0000000..4202a65 --- /dev/null +++ b/tests/exec/address3.out @@ -0,0 +1,3 @@ +x = 41 +x = 42 +x = 43 diff --git a/tests/exec/affect.cpp b/tests/exec/affect.cpp new file mode 100644 index 0000000..fd65fd1 --- /dev/null +++ b/tests/exec/affect.cpp @@ -0,0 +1,12 @@ +#include + +int main() { + int x = 0; + int y = 0; + x = ++y; + y = ++y + ++x; + y++; + x = --x + y; + std::cout << "x=" << x << "\n"; + std::cout << "y=" << y << "\n"; +} diff --git a/tests/exec/affect.out b/tests/exec/affect.out new file mode 100644 index 0000000..a6e2f7b --- /dev/null +++ b/tests/exec/affect.out @@ -0,0 +1,2 @@ +x=6 +y=5 diff --git a/tests/exec/arith1.cpp b/tests/exec/arith1.cpp new file mode 100644 index 0000000..2280f76 --- /dev/null +++ b/tests/exec/arith1.cpp @@ -0,0 +1,14 @@ +#include + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + x = x+1; + std::cout << "x = " << x << "\n"; + x = 2*x; + std::cout << "x = " << x << "\n"; + x = 2*x + 3; + std::cout << "x = " << x << "\n"; + x = 1 - 2*x; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/arith1.out b/tests/exec/arith1.out new file mode 100644 index 0000000..a397f16 --- /dev/null +++ b/tests/exec/arith1.out @@ -0,0 +1,5 @@ +x = 41 +x = 42 +x = 84 +x = 171 +x = -341 diff --git a/tests/exec/bst.cpp b/tests/exec/bst.cpp new file mode 100644 index 0000000..e5ccce8 --- /dev/null +++ b/tests/exec/bst.cpp @@ -0,0 +1,101 @@ + +#include + +// arbres binaires, où l'arbre vide est NULL + +class Node { +public: + int elt; + Node *left, *right; + Node(Node *left, int elt, Node *right); +}; + +Node::Node(Node *left, int elt, Node *right) { + this->left = left; + this->elt = elt; + this->right = right; +} + +int tree_size(Node *t) { + if (t == NULL) return 0; + return 1 + tree_size(t->left) + tree_size(t->right); +} + +Node *tree_add(Node *t, int x) { + if (t == NULL) return new Node(NULL, x, NULL); + if (x < t->elt) t->left = tree_add(t->left, x); + else if (x > t->elt) t->right = tree_add(t->right, x); + return t; +} + +void tree_add_ref(Node* &t, int x) { + if (t == NULL ) t = new Node(NULL, x, NULL); + else if (x < t->elt) tree_add_ref(t->left, x); + else if (x > t->elt) tree_add_ref(t->right, x); +} + +void tree_print(Node *t) { + if (t == NULL) return; + std::cout << "("; + tree_print(t->left); + std::cout << t->elt; + tree_print(t->right); + std::cout << ")"; +} + + +// encapsulation dans une classe + +class BST { +public: + Node *root; + BST(); + int size(); + void add1(int x); + void add2(int x); + void print(); +}; + +BST::BST() { + this->root = NULL; +} + +int BST::size() { + return tree_size(this->root); +} + +void BST::add1(int x) { + this->root = tree_add(this->root, x); +} + +void BST::add2(int x) { + tree_add_ref(this->root, x); +} + +void BST::print() { + tree_print(this->root); + std::cout << std::endl; +} + + +// tests + +int main() { + BST t; + t.add1(2); + t.add2(3); + t.add1(1); + t.print(); + t.add2(7); + t.add1(0); + t.print(); + BST *u = new BST(); + int i; + for (i = 0; i < 10; i++) + u->add1((31 * i) % 7); + u->print(); + for (i = 0; i < 10; i++) + u->add2((29 * i) % 13); + u->print(); + return 0; +} diff --git a/tests/exec/bst.out b/tests/exec/bst.out new file mode 100644 index 0000000..2795607 --- /dev/null +++ b/tests/exec/bst.out @@ -0,0 +1,4 @@ +((1)2(3)) +(((0)1)2(3(7))) +(0(((1)2)3(((4)5)6))) +(0(((1)2)3(((4)5)6((8)9((11)12))))) diff --git a/tests/exec/for1.cpp b/tests/exec/for1.cpp new file mode 100644 index 0000000..3ac56de --- /dev/null +++ b/tests/exec/for1.cpp @@ -0,0 +1,7 @@ +#include + +int main() { + int i; + for (i = 0; i < 10; i++) + std::cout << "i = " << i << "\n"; +} diff --git a/tests/exec/for1.out b/tests/exec/for1.out new file mode 100644 index 0000000..dc59d9b --- /dev/null +++ b/tests/exec/for1.out @@ -0,0 +1,10 @@ +i = 0 +i = 1 +i = 2 +i = 3 +i = 4 +i = 5 +i = 6 +i = 7 +i = 8 +i = 9 diff --git a/tests/exec/for2.cpp b/tests/exec/for2.cpp new file mode 100644 index 0000000..65ce735 --- /dev/null +++ b/tests/exec/for2.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int i; + for (i = 0; i < 10; i++) + std::cout << "i = " << i << "\n"; + std::cout << "i = " << i << "\n"; +} diff --git a/tests/exec/for2.out b/tests/exec/for2.out new file mode 100644 index 0000000..2bcca9c --- /dev/null +++ b/tests/exec/for2.out @@ -0,0 +1,11 @@ +i = 0 +i = 1 +i = 2 +i = 3 +i = 4 +i = 5 +i = 6 +i = 7 +i = 8 +i = 9 +i = 10 diff --git a/tests/exec/for3.cpp b/tests/exec/for3.cpp new file mode 100644 index 0000000..3df619c --- /dev/null +++ b/tests/exec/for3.cpp @@ -0,0 +1,11 @@ +#include + +int main() { + int i; + int j; + for (i = 0; i < 5; i++) + for (j = 0; j < 5; j++) + std::cout << "i*j = " << i*j << "\n"; + std::cout << "i = " << i << "\n"; + std::cout << "j = " << j << "\n"; +} diff --git a/tests/exec/for3.out b/tests/exec/for3.out new file mode 100644 index 0000000..6ed4dd6 --- /dev/null +++ b/tests/exec/for3.out @@ -0,0 +1,27 @@ +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 0 +i*j = 1 +i*j = 2 +i*j = 3 +i*j = 4 +i*j = 0 +i*j = 2 +i*j = 4 +i*j = 6 +i*j = 8 +i*j = 0 +i*j = 3 +i*j = 6 +i*j = 9 +i*j = 12 +i*j = 0 +i*j = 4 +i*j = 8 +i*j = 12 +i*j = 16 +i = 5 +j = 5 diff --git a/tests/exec/global.cpp b/tests/exec/global.cpp new file mode 100644 index 0000000..8a32a23 --- /dev/null +++ b/tests/exec/global.cpp @@ -0,0 +1,14 @@ +#include + +int x, *p; + +int main() { + x = 41; + std::cout << x << "\n"; + p = &x; + *p = *p + 1; + std::cout << x << "\n"; + int &r = x; + r = r + 1; + std::cout << x << "\n"; +} diff --git a/tests/exec/global.out b/tests/exec/global.out new file mode 100644 index 0000000..f91de27 --- /dev/null +++ b/tests/exec/global.out @@ -0,0 +1,3 @@ +41 +42 +43 diff --git a/tests/exec/hexa.cpp b/tests/exec/hexa.cpp new file mode 100644 index 0000000..70feac9 --- /dev/null +++ b/tests/exec/hexa.cpp @@ -0,0 +1,15 @@ +#include + +int main() { + std::cout << 0x100 << "\n"; + std::cout << 0xff << "\n"; + std::cout << 0xFF << "\n"; + int maxint = 0x7fffffff; + std::cout << maxint << "\n"; + int x = 0xDEADBEEF; + std::cout << x << "\n"; + x = 0xFFFFFFFF; + std::cout << x << "\n"; + x = 0x80000000; + std::cout << x << "\n"; +} diff --git a/tests/exec/hexa.out b/tests/exec/hexa.out new file mode 100644 index 0000000..2a5b25b --- /dev/null +++ b/tests/exec/hexa.out @@ -0,0 +1,7 @@ +256 +255 +255 +2147483647 +-559038737 +-1 +-2147483648 diff --git a/tests/exec/inheritance1.cpp b/tests/exec/inheritance1.cpp new file mode 100644 index 0000000..8a2c1e7 --- /dev/null +++ b/tests/exec/inheritance1.cpp @@ -0,0 +1,30 @@ +#include + +class A { +public: + virtual void f(); +}; + +class B : public A { +public: + void f(); +}; + +void A::f() { + std::cout << "this is A::f" << "\n"; +} + +void B::f() { + std::cout << "this is B::f" << "\n"; +} + +int main() { + A a; + a.f(); + B b; + b.f(); + A *x = &b; + x->f(); + x = &a; + x->f(); +} diff --git a/tests/exec/inheritance1.out b/tests/exec/inheritance1.out new file mode 100644 index 0000000..bb94fe2 --- /dev/null +++ b/tests/exec/inheritance1.out @@ -0,0 +1,4 @@ +this is A::f +this is B::f +this is B::f +this is A::f diff --git a/tests/exec/inheritance2.cpp b/tests/exec/inheritance2.cpp new file mode 100644 index 0000000..272b341 --- /dev/null +++ b/tests/exec/inheritance2.cpp @@ -0,0 +1,26 @@ +#include + +class A { +public: + virtual void f(); +}; + +class B : public A { +public: + void f(); +}; + +void A::f() { + std::cout << "this is A::f" << "\n"; +} + +void B::f() { + std::cout << "this is B::f" << "\n"; +} + +int main() { + A *a = new A(); + a->f(); + a = new B(); + a->f(); +} diff --git a/tests/exec/inheritance2.out b/tests/exec/inheritance2.out new file mode 100644 index 0000000..68820df --- /dev/null +++ b/tests/exec/inheritance2.out @@ -0,0 +1,2 @@ +this is A::f +this is B::f diff --git a/tests/exec/josephus.cpp b/tests/exec/josephus.cpp new file mode 100644 index 0000000..f43dac6 --- /dev/null +++ b/tests/exec/josephus.cpp @@ -0,0 +1,101 @@ +#include + +/*** listes circulaires doublement chaînées ***/ + +class ListeC { + public: + int valeur; + ListeC *suivant; + ListeC *precedent; + ListeC(int v); + void insererApres(int v); + void supprimer(); + void afficher(); +}; + +/* constructeur = liste réduite à un élément */ +ListeC::ListeC(int v) { + valeur = v; + suivant = precedent = this; +} + +/* insertion après un élément */ +void ListeC::insererApres(int v) { + ListeC *e = new ListeC(0); + e->valeur = v; + e->suivant = suivant; + suivant = e; + e->suivant->precedent = e; + e->precedent = this; +} + +/* suppression d'un élément */ +void ListeC::supprimer() { + precedent->suivant = suivant; + suivant->precedent = precedent; +} + +/* affichage */ +void ListeC::afficher() { + ListeC *c = this; + std::cout << c->valeur << " "; + c = c->suivant; + for (; c != this;) { + std::cout << c->valeur << " "; + c = c->suivant; + } + std::cout << "\n"; +} + +/*** problème de Josephus ***/ + +/* construction de la liste circulaire 1,2,...,n; + l'élément retourné est celui contenant 1 */ +ListeC *cercle(int n) { + ListeC *l = new ListeC(1); + int i; + for (i = n; i >= 2; i--) { + l->insererApres(i); + } + return l; +} + +/* jeu de Josephus */ +int josephus(int n, int p) { + /* c est le joueur courant, 1 au départ */ + ListeC *c = cercle(n); + + /* tant qu'il reste plus d'un joueur */ + for (; c != c->suivant;) { + /* on élimine un joueur */ + int i; + for (i = 1; i < p; i++) + c = c->suivant; + c->supprimer(); + // std::cout << c->valeur << " est éliminé"; + c = c->suivant; + } + // std::cout << "le gagnant est " << c->valeur; + return c->valeur; +} + +/*** Tests ***/ + +int main() { + ListeC l = ListeC(1); + l.afficher(); + l.insererApres(3); + l.afficher(); + l.insererApres(2); + l.afficher(); + l.suivant->supprimer(); + l.afficher(); + + ListeC *c = cercle(7); + c->afficher(); + + if (josephus(7, 5) == 6 && + josephus(5, 5) == 2 && + josephus(5, 17) == 4 && josephus(13, 2) == 11) + std::cout << "ok\n"; +} diff --git a/tests/exec/josephus.out b/tests/exec/josephus.out new file mode 100644 index 0000000..0506f80 --- /dev/null +++ b/tests/exec/josephus.out @@ -0,0 +1,6 @@ +1 +1 3 +1 2 3 +1 3 +1 2 3 4 5 6 7 +ok diff --git a/tests/exec/mandelbrot.cpp b/tests/exec/mandelbrot.cpp new file mode 100644 index 0000000..206b18b --- /dev/null +++ b/tests/exec/mandelbrot.cpp @@ -0,0 +1,60 @@ + +#include + +/* arithmetique de virgule fixe + precision q = 8192 i.e. 13 bits pour la partie decimale */ + +int add(int x, int y) { + return x + y; +} +int sub(int x, int y) { + return x - y; +} +int mul(int x, int y) { + int t = x * y; + return (t + 8192 / 2) / 8192; +} +int div(int x, int y) { + int t = x * 8192; + return (t + y / 2) / y; +} +int of_int(int x) { + return x * 8192; +} + +int iter(int n, int a, int b, int xn, int yn) { + if (n == 100) return true; + int xn2 = mul(xn, xn); + int yn2 = mul(yn, yn); + if (add(xn2, yn2) > of_int(4)) return false; + return iter(n+1, a, b, add(sub(xn2, yn2), a), + add(mul(of_int(2), mul(xn, yn)), b)); +} + +int inside(int x, int y) { + return iter(0, x, y, of_int(0), of_int(0)); +} + +int main() { + int steps = 30; + int xmin = of_int(-2); + int xmax = of_int(1); + int deltax = div(sub(xmax, xmin), of_int(2 * steps)); + int ymin = of_int(-1); + int ymax = of_int(1); + int deltay = div(sub(ymax, ymin), of_int(steps)); + int i; + for (i = 0; i < steps; i++) { + int y = add(ymin, mul(of_int(i), deltay)); + int j; + for (j = 0; j < 2 * steps; j++) { + int x = add(xmin, mul(of_int(j), deltax)); + if (inside(x, y)) + std::cout << "0"; + else + std::cout << "1"; + } + std::cout << "\n"; + } +} + diff --git a/tests/exec/mandelbrot.out b/tests/exec/mandelbrot.out new file mode 100644 index 0000000..11cc36c --- /dev/null +++ b/tests/exec/mandelbrot.out @@ -0,0 +1,30 @@ +111111111111111111111111111111111111111111111111111111111111 +111111111111111111111111111111111111111111111111111111111111 +111111111111111111111111111111111111110111111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111100111111111111111111111 +111111111111111111111111111111011000000000011111111111111111 +111111111111111111111111111110000000000000000001111111111111 +111111111111111111111111111110000000000000000011111111111111 +111111111111111111111111111100000000000000000001111111111111 +111111111111111111111111110000000000000000000000011111111111 +111111111111111110110111111000000000000000000000111111111111 +111111111111111110000000110000000000000000000000111111111111 +111111111111111100000000010000000000000000000000111111111111 +111111111111111100000000010000000000000000000001111111111111 +111110111100000000000000000000000000000000000111111111111111 +111111111111111100000000010000000000000000000000111111111111 +111111111111111100000000010000000000000000000000111111111111 +111111111111111110000000110000000000000000000000111111111111 +111111111111111110110111111000000000000000000000111111111111 +111111111111111111111111111000000000000000000000011111111111 +111111111111111111111111111100000000000000000001111111111111 +111111111111111111111111111110000000000000000011111111111111 +111111111111111111111111111111000000000000000001111111111111 +111111111111111111111111111111011000000000011111111111111111 +111111111111111111111111111111111111100111111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111000011111111111111111111 +111111111111111111111111111111111111110111111111111111111111 +111111111111111111111111111111111111111111111111111111111111 diff --git a/tests/exec/octal.cpp b/tests/exec/octal.cpp new file mode 100644 index 0000000..649ebde --- /dev/null +++ b/tests/exec/octal.cpp @@ -0,0 +1,13 @@ +#include + +int main() { + std::cout << 0100 << "\n"; + std::cout << 0777 << "\n"; + std::cout << 0644 << "\n"; + int maxint = 017777777777; + std::cout << maxint << "\n"; + int x = 037777777777; + std::cout << x << "\n"; + x = 020000000000; + std::cout << x << "\n"; +} diff --git a/tests/exec/octal.out b/tests/exec/octal.out new file mode 100644 index 0000000..ee77d8d --- /dev/null +++ b/tests/exec/octal.out @@ -0,0 +1,6 @@ +64 +511 +420 +2147483647 +-1 +-2147483648 diff --git a/tests/exec/pascal.cpp b/tests/exec/pascal.cpp new file mode 100644 index 0000000..a8a581e --- /dev/null +++ b/tests/exec/pascal.cpp @@ -0,0 +1,62 @@ + +// triangle de Pascal modulo 7 +// on n'a pas de tableaux, alors on utilise des listes chaînées + +#include + +class Array { +public: + int val; + Array *next; + Array(int n); // une liste à n éléments + int get(int i); + void set(int i, int v); +}; + +Array::Array(int n) { + if (n == 1) return; + next = new Array(n-1); +} + +int Array::get(int i) { + if (i == 0) return val; + return next->get(i-1); +} + +void Array::set(int i, int v) { + if (i == 0) val = v; + else next->set(i-1, v); +} + +void print_row(Array *r, int i) { + int j; + for (j = 0; j <= i; j++) { + if (r->get(j) != 0) + std::cout << "*"; + else + std::cout << "0"; + } + std::cout << "\n"; +} + +void compute_row(Array *r, int j) { + int v = 0; + if (j == 0) + v = 1; + else + v = (r->get(j) + r->get(j-1)) % 7; + r->set(j, v); + if (j > 0) + compute_row(r, j-1); +} + +int main() { + int h = 42; + Array *r = new Array(h+1); + int i; + for (i = 0; i < h; i++) { + r->set(i, 0); + compute_row(r, i); + print_row(r, i); + } +} diff --git a/tests/exec/pascal.out b/tests/exec/pascal.out new file mode 100644 index 0000000..58ca9bc --- /dev/null +++ b/tests/exec/pascal.out @@ -0,0 +1,42 @@ +* +** +*** +**** +***** +****** +******* +*000000* +**00000** +***0000*** +****000**** +*****00***** +******0****** +************** +*000000*000000* +**00000**00000** +***0000***0000*** +****000****000**** +*****00*****00***** +******0******0****** +********************* +*000000*000000*000000* +**00000**00000**00000** +***0000***0000***0000*** +****000****000****000**** +*****00*****00*****00***** +******0******0******0****** +**************************** +*000000*000000*000000*000000* +**00000**00000**00000**00000** +***0000***0000***0000***0000*** +****000****000****000****000**** +*****00*****00*****00*****00***** +******0******0******0******0****** +*********************************** +*000000*000000*000000*000000*000000* +**00000**00000**00000**00000**00000** +***0000***0000***0000***0000***0000*** +****000****000****000****000****000**** +*****00*****00*****00*****00*****00***** +******0******0******0******0******0****** +****************************************** diff --git a/tests/exec/passing.cpp b/tests/exec/passing.cpp new file mode 100644 index 0000000..6354fa5 --- /dev/null +++ b/tests/exec/passing.cpp @@ -0,0 +1,13 @@ +#include + +void incr(int &y) { + y = y+1; +} + +int main() { + int x = 5; + std::cout << "x = " << x << std::endl; + incr(x); + std::cout << "x = " << x << std::endl; +} + diff --git a/tests/exec/passing.out b/tests/exec/passing.out new file mode 100644 index 0000000..62226ae --- /dev/null +++ b/tests/exec/passing.out @@ -0,0 +1,2 @@ +x = 5 +x = 6 diff --git a/tests/exec/prepost1.cpp b/tests/exec/prepost1.cpp new file mode 100644 index 0000000..c536018 --- /dev/null +++ b/tests/exec/prepost1.cpp @@ -0,0 +1,14 @@ +#include + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + x++; + std::cout << "x = " << x << "\n"; + x--; + std::cout << "x = " << x << "\n"; + ++x; + std::cout << "x = " << x << "\n"; + --x; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/prepost1.out b/tests/exec/prepost1.out new file mode 100644 index 0000000..12ad2b0 --- /dev/null +++ b/tests/exec/prepost1.out @@ -0,0 +1,5 @@ +x = 41 +x = 42 +x = 41 +x = 42 +x = 41 diff --git a/tests/exec/ref1.cpp b/tests/exec/ref1.cpp new file mode 100644 index 0000000..f62d1f6 --- /dev/null +++ b/tests/exec/ref1.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int x = 41; + int &y = x; + y = 42; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/ref1.out b/tests/exec/ref1.out new file mode 100644 index 0000000..2d76aba --- /dev/null +++ b/tests/exec/ref1.out @@ -0,0 +1 @@ +x = 42 diff --git a/tests/exec/ref2.cpp b/tests/exec/ref2.cpp new file mode 100644 index 0000000..d4d2eb8 --- /dev/null +++ b/tests/exec/ref2.cpp @@ -0,0 +1,14 @@ +#include + +void f(int &y) { + y = 42; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + x = 41; + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/ref2.out b/tests/exec/ref2.out new file mode 100644 index 0000000..26f06b0 --- /dev/null +++ b/tests/exec/ref2.out @@ -0,0 +1,3 @@ +x = 41 +x = 42 +x = 41 diff --git a/tests/exec/ref3.cpp b/tests/exec/ref3.cpp new file mode 100644 index 0000000..ba58365 --- /dev/null +++ b/tests/exec/ref3.cpp @@ -0,0 +1,18 @@ +#include + +void f(int &y) { + y = y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + x = 0; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/ref3.out b/tests/exec/ref3.out new file mode 100644 index 0000000..65e2846 --- /dev/null +++ b/tests/exec/ref3.out @@ -0,0 +1,5 @@ +x = 41 +x = 42 +x = 43 +x = 0 +x = 1 diff --git a/tests/exec/ref4.cpp b/tests/exec/ref4.cpp new file mode 100644 index 0000000..4f59ef4 --- /dev/null +++ b/tests/exec/ref4.cpp @@ -0,0 +1,16 @@ +#include + +void f(int &y) { + y = y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + int &z = x; + f(z); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; +} diff --git a/tests/exec/ref4.out b/tests/exec/ref4.out new file mode 100644 index 0000000..771565f --- /dev/null +++ b/tests/exec/ref4.out @@ -0,0 +1,4 @@ +x = 41 +x = 42 +x = 43 +z = 43 diff --git a/tests/exec/ref5.cpp b/tests/exec/ref5.cpp new file mode 100644 index 0000000..1f9944b --- /dev/null +++ b/tests/exec/ref5.cpp @@ -0,0 +1,29 @@ +#include + +void f(int &y) { + y = y + 1; +} + +int main() { + int x = 41; + std::cout << "x = " << x << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + int &z = x; + f(z); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + int &u = z; + f(u); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + std::cout << "u = " << u << "\n"; + f(z); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + std::cout << "u = " << u << "\n"; + f(x); + std::cout << "x = " << x << "\n"; + std::cout << "z = " << z << "\n"; + std::cout << "u = " << u << "\n"; +} diff --git a/tests/exec/ref5.out b/tests/exec/ref5.out new file mode 100644 index 0000000..d52026a --- /dev/null +++ b/tests/exec/ref5.out @@ -0,0 +1,13 @@ +x = 41 +x = 42 +x = 43 +z = 43 +x = 44 +z = 44 +u = 44 +x = 45 +z = 45 +u = 45 +x = 46 +z = 46 +u = 46 diff --git a/tests/exec/ref6.cpp b/tests/exec/ref6.cpp new file mode 100644 index 0000000..3737786 --- /dev/null +++ b/tests/exec/ref6.cpp @@ -0,0 +1,20 @@ +#include + +int &f(int b, int &x, int &y) { + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; + if (b) return x; else return y; +} + +int main() { + int x = 42; + int y = 43; + int &r = f(1, x, y); + // now r is an alias for x + r = 12; + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; + f(0,x,y) = 13; + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; +} diff --git a/tests/exec/ref6.out b/tests/exec/ref6.out new file mode 100644 index 0000000..cb5da25 --- /dev/null +++ b/tests/exec/ref6.out @@ -0,0 +1,8 @@ +x = 42 +y = 43 +x = 12 +y = 43 +x = 12 +y = 43 +x = 12 +y = 13 diff --git a/tests/exec/string.cpp b/tests/exec/string.cpp new file mode 100644 index 0000000..38183b8 --- /dev/null +++ b/tests/exec/string.cpp @@ -0,0 +1,10 @@ +#include + +int main() { + std::cout << "abc\n"; + std::cout << "a\nc\n"; + std::cout << "a\\c\n"; + std::cout << "a\tc\n"; + std::cout << "a\"c\n"; + std::cout << "\x41\x42\x43\n"; +} diff --git a/tests/exec/string.out b/tests/exec/string.out new file mode 100644 index 0000000..0772ea1 --- /dev/null +++ b/tests/exec/string.out @@ -0,0 +1,7 @@ +abc +a +c +a\c +a c +a"c +ABC diff --git a/tests/exec/true_false.cpp b/tests/exec/true_false.cpp new file mode 100644 index 0000000..42a4f65 --- /dev/null +++ b/tests/exec/true_false.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int b = true; + std::cout << "b = " << b << "\n"; + b = false; + std::cout << "b = " << b << "\n"; +} diff --git a/tests/exec/true_false.out b/tests/exec/true_false.out new file mode 100644 index 0000000..1748f7d --- /dev/null +++ b/tests/exec/true_false.out @@ -0,0 +1,2 @@ +b = 1 +b = 0 diff --git a/tests/exec/vehicles.cpp b/tests/exec/vehicles.cpp new file mode 100644 index 0000000..51ab55d --- /dev/null +++ b/tests/exec/vehicles.cpp @@ -0,0 +1,78 @@ +#include + +class Vehicle { +public: + int position; + Vehicle(); + virtual void move(int d); +}; + +Vehicle::Vehicle() { + position = 10; +} + +void Vehicle::move(int d) { + std::cout << "vehicle moves\n"; + position = position + d; +} + + +class Car : public Vehicle { +public: + // champ position hérité + int passengers; + Car(); + // methode move() héritée + void await(Vehicle &v); +}; + +Car::Car() { +} + +void Car::await(Vehicle &v) { + std::cout << "await: position = " << v.position << "\n"; + if (v.position < position) + v.move(position - v.position); + else + move(10); +} + +class Truck : public Vehicle { +public: + // champ position hérité + int load; + Truck(); + void move(int d); +}; + +Truck::Truck() { +} + +void Truck::move(int d) { // methode move redéfinie + std::cout << "truck moves\n"; + if (d <= 55) position = position + d; else position = position + 55; +} + +int main() { + Truck t; + std::cout << "t at " << t.position << "\n"; + Car c; + c.passengers = 2; + std::cout << "c at " << c.position << "\n"; + c.move(60); + std::cout << "c at " << c.position << "\n"; + Vehicle *v = &c; // alias + v->move(70); + std::cout << "c at " << c.position << "\n"; + c.await(t); + std::cout << "t at " << t.position << "\n"; + std::cout << "c at " << c.position << "\n"; + +} + +/* +Local Variables: +compile-command: "make vehicles" +End: +*/ + diff --git a/tests/exec/vehicles.out b/tests/exec/vehicles.out new file mode 100644 index 0000000..b5f6c21 --- /dev/null +++ b/tests/exec/vehicles.out @@ -0,0 +1,10 @@ +t at 10 +c at 10 +vehicle moves +c at 70 +vehicle moves +c at 140 +await: position = 10 +truck moves +t at 65 +c at 140 -- cgit v1.2.3