From 77758165514c6eb7537285ab279eacea4e39c0a8 Mon Sep 17 00:00:00 2001 From: Ryan Potts Date: Sun, 30 Jun 2019 16:02:58 -0400 Subject: [PATCH 1/2] Pangram: update to v2.0.0 --- exercises/pangram/uPangramTests.pas | 46 ++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/exercises/pangram/uPangramTests.pas b/exercises/pangram/uPangramTests.pas index 1afdbfdb..9336ef2f 100644 --- a/exercises/pangram/uPangramTests.pas +++ b/exercises/pangram/uPangramTests.pas @@ -5,40 +5,40 @@ interface DUnitX.TestFramework; const - CanonicalVersion = '1.4.0'; + CanonicalVersion = '2.0.0'; type - [TestFixture] - PangramTests = class(TObject) + [TestFixture('isPangram')] + TPangramTests = class(TObject) public [Test] // [Ignore('Comment the "[Ignore]" statement to run the test')] - procedure sentence_empty; + procedure empty_sentence; [Test] [Ignore] - procedure recognizes_a_perfect_lower_case_pangram; + procedure perfect_lower_case; [Test] [Ignore] - procedure pangram_with_only_lower_case; + procedure only_lower_case; [Test] [Ignore] - procedure missing_character_x; + procedure missing_the_letter_x; [Test] [Ignore] - procedure another_missing_character_h; + procedure missing_the_letter_h; [Test] [Ignore] - procedure pangram_with_underscores; + procedure with_underscores; [Test] [Ignore] - procedure pangram_with_numbers; + procedure with_numbers; [Test] [Ignore] @@ -46,11 +46,11 @@ PangramTests = class(TObject) [Test] [Ignore] - procedure pangram_with_mixed_case_and_punctuation; + procedure mixed_case_and_punctuation; [Test] [Ignore] - procedure upper_and_lower_case_versions_of_the_same_character_should_not_be_counted_separately; + procedure case_insensitive; end; implementation @@ -58,56 +58,56 @@ implementation { PangramTests } -procedure PangramTests.sentence_empty; +procedure TPangramTests.empty_sentence; begin Assert.IsFalse(isPangram('')); end; -procedure PangramTests.recognizes_a_perfect_lower_case_pangram; +procedure TPangramTests.perfect_lower_case; begin Assert.IsTrue(isPangram('abcdefghijklmnopqrstuvwxyz')); end; -procedure PangramTests.pangram_with_only_lower_case; +procedure TPangramTests.only_lower_case; begin Assert.IsTrue(isPangram('the quick brown fox jumps over the lazy dog')); end; -procedure PangramTests.missing_character_x; +procedure TPangramTests.missing_the_letter_x; begin Assert.IsFalse(isPangram('a quick movement of the enemy will jeopardize five gunboats')); end; -procedure PangramTests.another_missing_character_h; +procedure TPangramTests.missing_the_letter_h; begin Assert.IsFalse(isPangram('five boxing wizards jump quickly at it')); end; -procedure PangramTests.pangram_with_underscores; +procedure TPangramTests.with_underscores; begin Assert.IsTrue(isPangram('the_quick_brown_fox_jumps_over_the_lazy_dog')); end; -procedure PangramTests.pangram_with_numbers; +procedure TPangramTests.with_numbers; begin Assert.IsTrue(isPangram('the 1 quick brown fox jumps over the 2 lazy dogs')); end; -procedure PangramTests.missing_letters_replaced_by_numbers; +procedure TPangramTests.missing_letters_replaced_by_numbers; begin Assert.IsFalse(isPangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog')); end; -procedure PangramTests.pangram_with_mixed_case_and_punctuation; +procedure TPangramTests.mixed_case_and_punctuation; begin Assert.IsTrue(isPangram('Five quacking Zephyrs jolt my wax bed.')); end; -procedure PangramTests.upper_and_lower_case_versions_of_the_same_character_should_not_be_counted_separately; +procedure TPangramTests.case_insensitive; begin Assert.IsFalse(isPangram('the quick brown fox jumps over with lazy FX')); end; initialization - TDUnitX.RegisterTestFixture(PangramTests); + TDUnitX.RegisterTestFixture(TPangramTests); end. From 2775dfd60b5016d226e195d6fe51025a6a108c06 Mon Sep 17 00:00:00 2001 From: Ryan Potts Date: Sun, 30 Jun 2019 16:08:19 -0400 Subject: [PATCH 2/2] Pangram: cleaned up example `aWords` never changes so should be const, utilized inline var declarations. --- exercises/pangram/uPangramExample.pas | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/exercises/pangram/uPangramExample.pas b/exercises/pangram/uPangramExample.pas index 2d501d45..2dfd0bdf 100644 --- a/exercises/pangram/uPangramExample.pas +++ b/exercises/pangram/uPangramExample.pas @@ -4,26 +4,21 @@ interface uses System.Generics.Collections; -function isPangram(aWords: string): Boolean; +function isPangram(const aWords: string): Boolean; implementation uses SysUtils; -function isPangram(aWords: string): Boolean; +function isPangram(const aWords: string): Boolean; const CAlphabetLength = 26; CFirstLetter = 'a'; CLastLetter = 'z'; -var - Letters: TList; - lChar: char; begin - result := false; - Letters := TList.Create; - Letters.Clear; + var Letters := TList.Create; try - for lChar in aWords.ToLowerInvariant do - if (lChar in [CFirstLetter..CLastLetter]) and not Letters.Contains(lChar) then + for var lChar in aWords.ToLowerInvariant do + if CharInSet(lChar, [CFirstLetter..CLastLetter]) and not Letters.Contains(lChar) then Letters.Add(lChar); result := Letters.Count = CAlphabetLength; finally