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