Skip to content
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
1 change: 1 addition & 0 deletions bin/auto-sync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ square-root
state-of-tic-tac-toe
strain
sublist
sum-of-multiples
swift-scheduling
transpose
tournament
Expand Down
3 changes: 2 additions & 1 deletion exercises/practice/sum-of-multiples/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"contributors": [
"arueckauer",
"kytrinyx",
"neenjaw"
"neenjaw",
"resu-xuniL"
],
"files": {
"solution": [
Expand Down
22 changes: 0 additions & 22 deletions exercises/practice/sum-of-multiples/.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 sumOfMultiples($number, $multiples)
Expand Down
13 changes: 10 additions & 3 deletions exercises/practice/sum-of-multiples/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[54aaab5a-ce86-4edc-8b40-d3ab2400a279]
description = "no multiples within limit"
Expand Down
137 changes: 100 additions & 37 deletions exercises/practice/sum-of-multiples/SumOfMultiplesTest.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
<?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);

use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase;

class SumOfMultiplesTest extends TestCase
Expand All @@ -33,63 +12,147 @@ public static function setUpBeforeClass(): void
require_once 'SumOfMultiples.php';
}

public function testSumToOne(): void
/**
* uuid: 54aaab5a-ce86-4edc-8b40-d3ab2400a279
*/
#[TestDox('No multiples within limit')]
public function testNoMultiplesWithinLimit(): void
{
$this->assertEquals(0, sumOfMultiples(1, [3, 5]));
}

public function testSumToThree(): void
/**
* uuid: 361e4e50-c89b-4f60-95ef-5bc5c595490a
*/
#[TestDox('One factor has multiples within limit')]
public function testOneFactorHasMultiplesWithinLimit(): void
{
$this->assertEquals(3, sumOfMultiples(4, [3, 5]));
}

public function testSumToTen(): void
/**
* uuid: e644e070-040e-4ae0-9910-93c69fc3f7ce
*/
#[TestDox('More than one multiple within limit')]
public function testMoreThanOneMultipleWithinLimit(): void
{
$this->assertEquals(23, sumOfMultiples(10, [3, 5]));
$this->assertEquals(9, sumOfMultiples(7, [3]));
}

public function testSumToTwenty(): void
/**
* uuid: 607d6eb9-535c-41ce-91b5-3a61da3fa57f
*/
#[TestDox('More than one factor with multiples within limit')]
public function testMoreThanOneFactorWithMultiplesWithinLimit(): void
{
$this->assertEquals(78, sumOfMultiples(20, [3, 5]));
$this->assertEquals(23, sumOfMultiples(10, [3, 5]));
}

public function testSumToHundred(): void
/**
* uuid: f47e8209-c0c5-4786-b07b-dc273bf86b9b
*/
#[TestDox('Each multiple is only counted once')]
public function testEachMultipleIsOnlyCountedOnce(): void
{
$this->assertEquals(2318, sumOfMultiples(100, [3, 5]));
}

public function testSumToThousand(): void
/**
* uuid: 28c4b267-c980-4054-93e9-07723db615ac
*/
#[TestDox('A much larger limit')]
public function testAMuchLargerLimit(): void
{
$this->assertEquals(233168, sumOfMultiples(1000, [3, 5]));
}

public function testConfigureToTwenty(): void
/**
* uuid: 09c4494d-ff2d-4e0f-8421-f5532821ee12
*/
#[TestDox('Three factors')]
public function testThreeFactors(): void
{
$this->assertEquals(51, sumOfMultiples(20, [7, 13, 17]));
}

public function testConfigureToFifteen(): void
/**
* uuid: 2d0d5faa-f177-4ad6-bde9-ebb865083751
*/
#[TestDox('Factors not relatively prime')]
public function testFactorsNotRelativelyPrime(): void
{
$this->assertEquals(30, sumOfMultiples(15, [4, 6]));
}

public function testConfigureToOneFifty(): void
/**
* uuid: ece8f2e8-96aa-4166-bbb7-6ce71261e354
*/
#[TestDox('Some pairs of factors relatively prime and some not')]
public function testSomePairsOfFactorsRelativelyPrimeAndSomeNot(): void
{
$this->assertEquals(4419, sumOfMultiples(150, [5, 6, 8]));
}

public function testConfigureToFortySeven(): void
/**
* uuid: 624fdade-6ffb-400e-8472-456a38c171c0
*/
#[TestDox('One factor is a multiple of another')]
public function testOneFactorIsAMultipleOfAnother(): void
{
$this->assertEquals(275, sumOfMultiples(51, [5, 25]));
}

/**
* uuid: 949ee7eb-db51-479c-b5cb-4a22b40ac057
*/
#[TestDox('Much larger factors')]
public function testMuchLargerFactors(): void
{
$this->assertEquals(2203160, sumOfMultiples(10000, [43, 47]));
}

public function testMultiplesOfOneToHundred(): void
/**
* uuid: 41093673-acbd-482c-ab80-d00a0cbedecd
*/
#[TestDox('All numbers are multiples of 1')]
public function testAllNumbersAreMultiplesOf1(): void
{
$this->assertEquals(4950, sumOfMultiples(100, [1]));
}

public function testMultiplesOfEmptyList(): void
/**
* uuid: 1730453b-baaa-438e-a9c2-d754497b2a76
*/
#[TestDox('No factors means an empty sum')]
public function testNoFactorsMeansAnEmptySum(): void
{
$this->assertEquals(0, sumOfMultiples(10000, []));
}

/**
* uuid: 214a01e9-f4bf-45bb-80f1-1dce9fbb0310
*/
#[TestDox('The only multiple of 0 is 0')]
public function testTheOnlyMultipleOf0Is0(): void
{
$this->assertEquals(0, sumOfMultiples(1, [0]));
}

/**
* uuid: c423ae21-a0cb-4ec7-aeb1-32971af5b510
*/
#[TestDox('The factor 0 does not affect the sum of multiples of other factors')]
public function testTheFactor0DoesNotAffectTheSumOfMultiplesOfOtherFactors(): void
{
$this->assertEquals(3, sumOfMultiples(4, [3, 0]));
}

/**
* uuid: 17053ba9-112f-4ac0-aadb-0519dd836342
*/
#[TestDox('Solutions using include-exclude must extend to cardinality greater than 3')]
public function testSolutionsUsingIncludeExcludeMustExtendToCardinalityGreaterThan3(): void
{
$this->assertEquals(0, sumOfMultiples(1000, [0]));
$this->assertEquals(39614537, sumOfMultiples(10000, [2, 3, 5, 7, 11]));
}
}
Loading