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

Sync difference of squares #681

Merged
merged 5 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ The square of the sum of the first ten natural numbers is
The sum of the squares of the first ten natural numbers is
1² + 2² + ... + 10² = 385.

Hence the difference between the square of the sum of the first
ten natural numbers and the sum of the squares of the first ten
natural numbers is 3025 - 385 = 2640.
Hence the difference between the square of the sum of the first ten natural numbers and the sum of the squares of the first ten natural numbers is 3025 - 385 = 2640.

You are not expected to discover an efficient solution to this yourself from
first principles; research is allowed, indeed, encouraged. Finding the best
algorithm for the problem is a key skill in software engineering.
You are not expected to discover an efficient solution to this yourself from first principles; research is allowed, indeed, encouraged.
Finding the best algorithm for the problem is a key skill in software engineering.
3 changes: 2 additions & 1 deletion exercises/practice/difference-of-squares/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"kytrinyx",
"lafent",
"petemcfarlane",
"Scientifica96"
"Scientifica96",
"mk-mxp"
],
"files": {
"solution": [
Expand Down
22 changes: 0 additions & 22 deletions exercises/practice/difference-of-squares/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function squareOfSum($max)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class DifferenceOfSquaresTest extends PHPUnit\Framework\TestCase
Expand All @@ -31,46 +9,82 @@ public static function setUpBeforeClass(): void
require_once 'DifferenceOfSquares.php';
}

public function testSquareOfSumTo5(): void
/**
* uuid e46c542b-31fc-4506-bcae-6b62b3268537
* @testdox Square of sum 1
*/
public function testSquareOfSumTo1(): void
{
$this->assertEquals(225, squareOfSum(5));
$this->assertEquals(1, squareOfSum(1));
}

public function testSumOfSquaresTo5(): void
/**
* uuid 9b3f96cb-638d-41ee-99b7-b4f9c0622948
* @testdox Square of sum 5
*/
public function testSquareOfSumTo5(): void
{
$this->assertEquals(55, sumOfSquares(5));
$this->assertEquals(225, squareOfSum(5));
}

public function testDifferenceOfSumTo5(): void
/**
* uuid 54ba043f-3c35-4d43-86ff-3a41625d5e86
* @testdox Square of sum 100
*/
public function testSquareOfSumTo100(): void
{
$this->assertEquals(170, difference(5));
$this->assertEquals(25502500, squareOfSum(100));
}

public function testSquareOfSumTo10(): void
/**
* uuid 01d84507-b03e-4238-9395-dd61d03074b5
* @testdox Sum of squares 1
*/
public function testSumOfSquaresTo1(): void
{
$this->assertEquals(3025, squareOfSum(10));
$this->assertEquals(1, sumOfSquares(1));
}

public function testSumOfSquaresTo10(): void
/**
* uuid c93900cd-8cc2-4ca4-917b-dd3027023499
* @testdox Sum of squares 5
*/
public function testSumOfSquaresTo5(): void
{
$this->assertEquals(385, sumOfSquares(10));
$this->assertEquals(55, sumOfSquares(5));
}

public function testDifferenceOfSumTo10(): void
/**
* uuid 94807386-73e4-4d9e-8dec-69eb135b19e4
* @testdox Sum of squares 100
*/
public function testSumOfSquaresTo100(): void
{
$this->assertEquals(2640, difference(10));
$this->assertEquals(338350, sumOfSquares(100));
}

public function testSquareOfSumTo100(): void
/**
* uuid 44f72ae6-31a7-437f-858d-2c0837adabb6
* @testdox Difference of squares 1
*/
public function testDifferenceOfSumTo1(): void
{
$this->assertEquals(25502500, squareOfSum(100));
$this->assertEquals(0, difference(1));
}

public function testSumOfSquaresTo100(): void
/**
* uuid 005cb2bf-a0c8-46f3-ae25-924029f8b00b
* @testdox Difference of squares 5
*/
public function testDifferenceOfSumTo5(): void
{
$this->assertEquals(338350, sumOfSquares(100));
$this->assertEquals(170, difference(5));
}

/**
* uuid b1bf19de-9a16-41c0-a62b-1f02ecc0b036
* @testdox Difference of squares 100
*/
public function testDifferenceOfSumTo100(): void
{
$this->assertEquals(25164150, difference(100));
Expand Down