Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference of squares: sync expected test results and input data with problem-specifications #1791

Merged
merged 6 commits into from
May 31, 2019
Merged
6 changes: 3 additions & 3 deletions exercises/difference-of-squares/difference_of_squares.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
def square_of_sum(count):
def square_of_sum(number):
pass


def sum_of_squares(count):
def sum_of_squares(number):
pass


def difference(count):
def difference(number):
pass
9 changes: 5 additions & 4 deletions exercises/difference-of-squares/difference_of_squares_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from difference_of_squares import difference, square_of_sum, sum_of_squares
from difference_of_squares import difference_of_squares, \
square_of_sum, sum_of_squares
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is preferable to use parenthesis instead of backslashes for multiline imports. Example:

from difference_of_squares import (
	difference_of_squares,
	square_of_sum,
	sum_of_squares,
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops. I did not see this, or I wouldn't have closed this and deleted the branch. I am an idiot. :P Will re-open and correct!



# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
Expand All @@ -25,13 +26,13 @@ def test_sum_of_squares_100(self):
self.assertEqual(sum_of_squares(100), 338350)

def test_difference_of_squares_1(self):
self.assertEqual(difference(1), 0)
self.assertEqual(difference_of_squares(1), 0)

def test_difference_of_squares_5(self):
self.assertEqual(difference(5), 170)
self.assertEqual(difference_of_squares(5), 170)

def test_difference_of_squares_100(self):
self.assertEqual(difference(100), 25164150)
self.assertEqual(difference_of_squares(100), 25164150)


if __name__ == '__main__':
Expand Down
13 changes: 7 additions & 6 deletions exercises/difference-of-squares/example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
def square_of_sum(count):
sum_ = count * (count + 1) / 2
def square_of_sum(number):
sum_ = number * (number + 1) / 2
return sum_ * sum_


def sum_of_squares(count):
return sum(m * m for m in range(count + 1))
def sum_of_squares(number):
numerator = number * (number + 1) * (2 * number + 1)
return numerator/6


def difference(count):
return square_of_sum(count) - sum_of_squares(count)
def difference_of_squares(number):
return square_of_sum(number) - sum_of_squares(number)