2 ** polynomial_adt_test.c
3 ** Test (minimalistic) for the polynomial module
4 * More of a display of functionality
5 * Copyright (c) 2009 I. Soule
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 ** iasoule32@gmail.com
33 #include "../polynomial_adt.h"
34 #include "../polynomial_adt.c"
38 PolyAdt *p = create_adt(5), *q = create_adt(4);
39 PolyAdt *sum, *diff, *prod;
53 printf("Displaying Polynomials ...\n");
58 printf("P(x) + Q(x) = ");
62 printf("P(x) - Q(x) = ");
66 printf("P(x)*Q(x) = ");
69 PolyAdt *quad = create_adt(2);
70 insert_term(quad, 10, 2);
71 insert_term(quad, 30, 1);
72 insert_term(quad, 2, 0);
74 quadratic_roots(quad, NULL, NULL); //print out the roots
77 quadratic_roots(quad, &real, &cplx);
79 printf("X1 = %f, X2 = %f\n\n", real, cplx);
81 PolyAdt *deriv, *integral;
83 deriv = derivative(p);
84 printf("The derivitive of p = ");
86 integral = integrate(q);
88 printf("The integral of q = ");
89 display_poly(integral);
91 printf("\n Computing P(x)^3\n");
94 expo = exponentiate(p, 3);
98 printf("Computing Integral[Q(x)^2]\n");
99 expo = exponentiate(q, 2);
100 integral = integrate(expo);
101 display_poly(integral);
104 printf(" Differentiating and Integrating P\n");
105 display_poly(integrate(derivative(p)));
109 L = create_adt(3), M = create_adt(2);
111 insert_term(L, 4, 3);
112 insert_term(L, 10, 2);
113 insert_term(L, 15, 1);
115 insert_term(M, 4, 2);
122 printf("Computing composition L(M(X))\n");
123 display_poly(compose(L, M));
125 printf("Freed memory back to heap for allocated polys'\n");
129 destroy_poly(L); destroy_poly(M);
130 destroy_poly(q); destroy_poly(p);