|
| 1 | +/* |
| 2 | + * Copyright 2014-2024 Brett Slatkin, Pearson Education Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <assert.h> |
| 18 | +#include <math.h> |
| 19 | +#include <stdio.h> |
| 20 | +#include "my_library.h" |
| 21 | + |
| 22 | + |
| 23 | +int main(int argc, char** argv) { |
| 24 | + { |
| 25 | + double a[] = {3, 4, 5}; |
| 26 | + double b[] = {-1, 9, -2.5}; |
| 27 | + double found = dot_product(3, a, b); |
| 28 | + double expected = 20.5; |
| 29 | + printf("Found %f, Expected %f\n", found, expected); |
| 30 | + assert(fabs(found - expected) < 0.01); |
| 31 | + } |
| 32 | + |
| 33 | + { |
| 34 | + double a[] = {0, 0, 0}; |
| 35 | + double b[] = {1, 1, 1}; |
| 36 | + double found = dot_product(3, a, b); |
| 37 | + double expected = 0; |
| 38 | + printf("Found %f, Expected %f\n", found, expected); |
| 39 | + assert(fabs(found - expected) < 0.01); |
| 40 | + } |
| 41 | + |
| 42 | + { |
| 43 | + double a[] = {-1, -1, -1}; |
| 44 | + double b[] = {1, 1, 1}; |
| 45 | + double found = dot_product(3, a, b); |
| 46 | + double expected = -3; |
| 47 | + printf("Found %f, Expected %f\n", found, expected); |
| 48 | + assert(fabs(found - expected) < 0.01); |
| 49 | + } |
| 50 | + |
| 51 | + return 0; |
| 52 | +} |
0 commit comments