Skip to content

Commit

Permalink
c/difference-of-squares: 2nd iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Jul 9, 2023
1 parent 7176ed9 commit a006d24
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
4 changes: 2 additions & 2 deletions c/difference-of-squares/difference_of_squares.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ unsigned int sum_of_squares(unsigned int number) {
}

unsigned int square_of_sum(unsigned int number) {
float numf = (float)number;
unsigned int sum = number * (number + 1) / 2;

return (unsigned int)powf(numf * (numf + 1.0F) / 2.0F, 2);
return sum * sum;
}

unsigned int difference_of_squares(unsigned int number) {
Expand Down
91 changes: 91 additions & 0 deletions c/difference-of-squares/run-tests-c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Running automated test file(s):


===============================================================================

Running: make clean
rm -rf *.o *.out *.out.dSYM

real 0m0.007s
user 0m0.001s
sys 0m0.005s

===============================================================================

Running: make test | ansifilter
Compiling tests.out
test_difference_of_squares.c:55:test_square_of_sum_1:PASS
test_difference_of_squares.c:56:test_square_of_sum_5:PASS
test_difference_of_squares.c:57:test_square_of_sum_100:PASS
test_difference_of_squares.c:58:test_sum_of_squares_1:PASS
test_difference_of_squares.c:59:test_sum_of_squares_5:PASS
test_difference_of_squares.c:60:test_sum_of_squares_100:PASS
test_difference_of_squares.c:61:test_difference_of_squares_1:PASS
test_difference_of_squares.c:62:test_difference_of_squares_5:PASS
test_difference_of_squares.c:63:test_difference_of_squares_100:PASS

-----------------------
9 Tests 0 Failures 0 Ignored
OK

real 0m0.118s
user 0m0.075s
sys 0m0.046s

===============================================================================

Running: make memcheck | ansifilter
Compiling memcheck
test_difference_of_squares.c:55:test_square_of_sum_1:PASS
test_difference_of_squares.c:56:test_square_of_sum_5:PASS
test_difference_of_squares.c:57:test_square_of_sum_100:PASS
test_difference_of_squares.c:58:test_sum_of_squares_1:PASS
test_difference_of_squares.c:59:test_sum_of_squares_5:PASS
test_difference_of_squares.c:60:test_sum_of_squares_100:PASS
test_difference_of_squares.c:61:test_difference_of_squares_1:PASS
test_difference_of_squares.c:62:test_difference_of_squares_5:PASS
test_difference_of_squares.c:63:test_difference_of_squares_100:PASS

-----------------------
9 Tests 0 Failures 0 Ignored
OK
Memory check passed

real 0m0.130s
user 0m0.097s
sys 0m0.034s

===============================================================================

Running: clang-format-16 -style=file -i ./difference_of_squares.c ./test_difference_of_squares.c ./difference_of_squares.h

real 0m0.020s
user 0m0.008s
sys 0m0.012s

===============================================================================

Running: clang-check-16 ./difference_of_squares.c ./test_difference_of_squares.c ./difference_of_squares.h --

real 0m0.037s
user 0m0.026s
sys 0m0.010s

===============================================================================

Running: clang-tidy-16 ./difference_of_squares.c ./test_difference_of_squares.c ./difference_of_squares.h -checks=*,-llvm-header-guard,-llvmlibc-restrict-system-libc-headers -- | head -n 100
1084 warnings generated.
3236 warnings generated.
4318 warnings generated.
Suppressed 4316 warnings (4316 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
/home/vpayno/git_vpayno/exercism-workspace/c/difference-of-squares/difference_of_squares.c:4:56: warning: 6 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
return (number * (number + 1) * (2 * number + 1) / 6);
^

real 0m0.178s
user 0m0.159s
sys 0m0.020s

===============================================================================

0 comments on commit a006d24

Please sign in to comment.