From 7a880aac31994381df56c7414b40c4ba310cc8d6 Mon Sep 17 00:00:00 2001 From: Rob Keim Date: Sun, 10 Dec 2017 15:08:46 +0700 Subject: [PATCH 1/3] Update out-of-date canonical data --- exercises/bob/BobTest.cs | 4 ++-- exercises/book-store/BookStoreTest.cs | 9 +++++++- .../rna-transcription/RnaTranscriptionTest.cs | 21 +------------------ exercises/word-count/WordCountTest.cs | 12 +++++++++++ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/exercises/bob/BobTest.cs b/exercises/bob/BobTest.cs index 33d609e019..3d1cbcdbbd 100644 --- a/exercises/bob/BobTest.cs +++ b/exercises/bob/BobTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; @@ -55,7 +55,7 @@ public void Using_acronyms_in_regular_speech() [Fact(Skip = "Remove to run test")] public void Forceful_question() { - Assert.Equal("Whoa, chill out!", Bob.Response("WHAT THE HELL WERE YOU THINKING?")); + Assert.Equal("Calm down, I know what I'm doing!", Bob.Response("WHAT THE HELL WERE YOU THINKING?")); } [Fact(Skip = "Remove to run test")] diff --git a/exercises/book-store/BookStoreTest.cs b/exercises/book-store/BookStoreTest.cs index d8f15bf5af..dc402164d1 100644 --- a/exercises/book-store/BookStoreTest.cs +++ b/exercises/book-store/BookStoreTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.1 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; @@ -94,4 +94,11 @@ public void Three_each_of_first_2_books_and_2_each_of_remaining_books() var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 2 }; Assert.Equal(75.2, BookStore.Total(basket)); } + + [Fact(Skip = "Remove to run test")] + public void Four_groups_of_four_are_cheaper_than_two_groups_each_of_five_and_three() + { + var basket = new[] { 1, 1, 2, 2, 3, 3, 4, 5, 1, 1, 2, 2, 3, 3, 4, 5 }; + Assert.Equal(102.4, BookStore.Total(basket)); + } } \ No newline at end of file diff --git a/exercises/rna-transcription/RnaTranscriptionTest.cs b/exercises/rna-transcription/RnaTranscriptionTest.cs index 68148c5e7c..64956d91dd 100644 --- a/exercises/rna-transcription/RnaTranscriptionTest.cs +++ b/exercises/rna-transcription/RnaTranscriptionTest.cs @@ -1,7 +1,6 @@ -// This file was auto-generated based on version 1.0.1 of the canonical data. +// This file was auto-generated based on version 1.1.0 of the canonical data. using Xunit; -using System; public class RnaTranscriptionTest { @@ -34,22 +33,4 @@ public void Rna_complement() { Assert.Equal("UGCACCAGAAUU", RnaTranscription.ToRna("ACGTGGTCTTAA")); } - - [Fact(Skip = "Remove to run test")] - public void Correctly_handles_invalid_input_rna_instead_of_dna_() - { - Assert.Throws(() => RnaTranscription.ToRna("U")); - } - - [Fact(Skip = "Remove to run test")] - public void Correctly_handles_completely_invalid_dna_input() - { - Assert.Throws(() => RnaTranscription.ToRna("XXX")); - } - - [Fact(Skip = "Remove to run test")] - public void Correctly_handles_partially_invalid_dna_input() - { - Assert.Throws(() => RnaTranscription.ToRna("ACGTXXXCTTAA")); - } } \ No newline at end of file diff --git a/exercises/word-count/WordCountTest.cs b/exercises/word-count/WordCountTest.cs index 0f3703911e..d95b99f2c9 100644 --- a/exercises/word-count/WordCountTest.cs +++ b/exercises/word-count/WordCountTest.cs @@ -140,4 +140,16 @@ public void With_quotations() }; Assert.Equal(expected, actual); } + + [Fact(Skip = "Remove to run test")] + public void Multiple_spaces_not_detected_as_a_word() + { + var actual = WordCount.Countwords(" multiple whitespaces"); + var expected = new Dictionary + { + ["multiple"] = 1, + ["whitespaces"] = 1 + }; + Assert.Equal(expected, actual); + } } \ No newline at end of file From eaeefaa6f78fa99ce5ab1b28af9a279669c44914 Mon Sep 17 00:00:00 2001 From: Rob Keim Date: Sun, 10 Dec 2017 15:53:34 +0700 Subject: [PATCH 2/3] Add ArmstrongNumbers exercise --- config.json | 10 ++++ exercises/Exercises.sln | 8 ++- .../armstrong-numbers/ArmstrongNumbers.cs | 9 ++++ .../armstrong-numbers/ArmstrongNumbers.csproj | 17 ++++++ .../armstrong-numbers/ArmstrongNumbersTest.cs | 54 +++++++++++++++++++ exercises/armstrong-numbers/Example.cs | 18 +++++++ exercises/armstrong-numbers/README.md | 10 ++++ generators/Exercises/ArmstrongNumbers.cs | 6 +++ 8 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 exercises/armstrong-numbers/ArmstrongNumbers.cs create mode 100644 exercises/armstrong-numbers/ArmstrongNumbers.csproj create mode 100644 exercises/armstrong-numbers/ArmstrongNumbersTest.cs create mode 100644 exercises/armstrong-numbers/Example.cs create mode 100644 exercises/armstrong-numbers/README.md create mode 100644 generators/Exercises/ArmstrongNumbers.cs diff --git a/config.json b/config.json index 0421ce0a34..66e41cd1ca 100644 --- a/config.json +++ b/config.json @@ -125,6 +125,16 @@ "unlocked_by": "sum-of-multiples", "uuid": "c4efbf8a-8e76-4700-807d-830a4938f4d0" }, + { + "core": false, + "difficulty": 2, + "slug": "armstrong-numbers", + "topics": [ + "mathematics" + ], + "unlocked_by": "sum-of-multiples", + "uuid": "8150604d-4cdc-414a-a523-dd65ac536f0e" + }, { "core": true, "difficulty": 3, diff --git a/exercises/Exercises.sln b/exercises/Exercises.sln index cc23654e9f..a6290eb394 100644 --- a/exercises/Exercises.sln +++ b/exercises/Exercises.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27004.2008 +VisualStudioVersion = 15.0.27004.2009 MinimumVisualStudioVersion = 15.0.26124.0 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Accumulate", "accumulate\Accumulate.csproj", "{F16C0EE1-6923-4328-B015-363CF24FF867}" EndProject @@ -224,6 +224,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IsbnVerifier", "isbn-verifi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReverseString", "reverse-string\ReverseString.csproj", "{D2105979-EE3B-432B-8016-172BA949DE2F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArmstrongNumbers", "armstrong-numbers\ArmstrongNumbers.csproj", "{7015C2C4-4050-4631-9394-7EAF19AB0191}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -674,6 +676,10 @@ Global {D2105979-EE3B-432B-8016-172BA949DE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D2105979-EE3B-432B-8016-172BA949DE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D2105979-EE3B-432B-8016-172BA949DE2F}.Release|Any CPU.Build.0 = Release|Any CPU + {7015C2C4-4050-4631-9394-7EAF19AB0191}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7015C2C4-4050-4631-9394-7EAF19AB0191}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7015C2C4-4050-4631-9394-7EAF19AB0191}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7015C2C4-4050-4631-9394-7EAF19AB0191}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/exercises/armstrong-numbers/ArmstrongNumbers.cs b/exercises/armstrong-numbers/ArmstrongNumbers.cs new file mode 100644 index 0000000000..b2ec353bb1 --- /dev/null +++ b/exercises/armstrong-numbers/ArmstrongNumbers.cs @@ -0,0 +1,9 @@ +using System; + +public static class ArmstrongNumbers +{ + public static bool IsArmstrongNumber(int number) + { + throw new NotImplementedException("You need to implement this function."); + } +} \ No newline at end of file diff --git a/exercises/armstrong-numbers/ArmstrongNumbers.csproj b/exercises/armstrong-numbers/ArmstrongNumbers.csproj new file mode 100644 index 0000000000..082b3bbe5f --- /dev/null +++ b/exercises/armstrong-numbers/ArmstrongNumbers.csproj @@ -0,0 +1,17 @@ + + + + netcoreapp2.0 + + + + + + + + + + + + + diff --git a/exercises/armstrong-numbers/ArmstrongNumbersTest.cs b/exercises/armstrong-numbers/ArmstrongNumbersTest.cs new file mode 100644 index 0000000000..bbc3cc05ff --- /dev/null +++ b/exercises/armstrong-numbers/ArmstrongNumbersTest.cs @@ -0,0 +1,54 @@ +// This file was auto-generated based on version 1.0.0 of the canonical data. + +using Xunit; + +public class ArmstrongNumbersTest +{ + [Fact] + public void Single_digit_numbers_are_armstrong_numbers() + { + Assert.True(ArmstrongNumbers.IsArmstrongNumber(5)); + } + + [Fact(Skip = "Remove to run test")] + public void There_are_no_2_digit_armstrong_numbers() + { + Assert.False(ArmstrongNumbers.IsArmstrongNumber(10)); + } + + [Fact(Skip = "Remove to run test")] + public void Three_digit_number_that_is_an_armstrong_number() + { + Assert.True(ArmstrongNumbers.IsArmstrongNumber(153)); + } + + [Fact(Skip = "Remove to run test")] + public void Three_digit_number_that_is_not_an_armstrong_number() + { + Assert.False(ArmstrongNumbers.IsArmstrongNumber(100)); + } + + [Fact(Skip = "Remove to run test")] + public void Four_digit_number_that_is_an_armstrong_number() + { + Assert.True(ArmstrongNumbers.IsArmstrongNumber(9474)); + } + + [Fact(Skip = "Remove to run test")] + public void Four_digit_number_that_is_not_an_armstrong_number() + { + Assert.False(ArmstrongNumbers.IsArmstrongNumber(9475)); + } + + [Fact(Skip = "Remove to run test")] + public void Seven_digit_number_that_is_an_armstrong_number() + { + Assert.True(ArmstrongNumbers.IsArmstrongNumber(9926315)); + } + + [Fact(Skip = "Remove to run test")] + public void Seven_digit_number_that_is_not_an_armstrong_number() + { + Assert.False(ArmstrongNumbers.IsArmstrongNumber(9926314)); + } +} \ No newline at end of file diff --git a/exercises/armstrong-numbers/Example.cs b/exercises/armstrong-numbers/Example.cs new file mode 100644 index 0000000000..679797cb45 --- /dev/null +++ b/exercises/armstrong-numbers/Example.cs @@ -0,0 +1,18 @@ +using System; + +public static class ArmstrongNumbers +{ + public static bool IsArmstrongNumber(int number) + { + var numString = number.ToString(); + var length = numString.Length; + + double total = 0; + for (int i = 0; i < length; i++) + { + total += Math.Pow(int.Parse(numString[i].ToString()), length); + } + + return number == (int)total; + } +} \ No newline at end of file diff --git a/exercises/armstrong-numbers/README.md b/exercises/armstrong-numbers/README.md new file mode 100644 index 0000000000..344b65fb4e --- /dev/null +++ b/exercises/armstrong-numbers/README.md @@ -0,0 +1,10 @@ +An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits. + +For example: + +- 9 is an Armstrong number, because `9 = 9^1 = 9` +- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 2` +- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153` +- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190` + +Write some code to determine whether a number is an Armstrong number. \ No newline at end of file diff --git a/generators/Exercises/ArmstrongNumbers.cs b/generators/Exercises/ArmstrongNumbers.cs new file mode 100644 index 0000000000..e3235cb727 --- /dev/null +++ b/generators/Exercises/ArmstrongNumbers.cs @@ -0,0 +1,6 @@ +namespace Generators.Exercises +{ + public class ArmstrongNumbers : GeneratorExercise + { + } +} \ No newline at end of file From bbb8334ad02d477ef4e6662fe066a3679ee4cdb2 Mon Sep 17 00:00:00 2001 From: Rob Keim Date: Sun, 10 Dec 2017 16:14:10 +0700 Subject: [PATCH 3/3] Update example implementation for Bob exercise --- exercises/bob/Example.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exercises/bob/Example.cs b/exercises/bob/Example.cs index f915c77d77..48eecc35f7 100644 --- a/exercises/bob/Example.cs +++ b/exercises/bob/Example.cs @@ -4,6 +4,8 @@ public static string Response(string statement) { if (IsSilence(statement)) return "Fine. Be that way!"; + if (IsYelling(statement) && IsQuestion(statement)) + return "Calm down, I know what I'm doing!"; if (IsYelling(statement)) return "Whoa, chill out!"; if (IsQuestion(statement))