🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of n0mn0m

n0mn0m's solution

to Pangram in the C# Track

Published at Nov 02 2020 · 0 comments
Instructions
Test suite
Solution

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.

Running the tests

To run the tests, run the command dotnet test from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the Skip property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using exercism submit Pangram.cs

Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.

Source

Wikipedia https://en.wikipedia.org/wiki/Pangram

PangramTests.cs

// This file was auto-generated based on version 2.0.0 of the canonical data.

using Xunit;

public class PangramTests
{
    [Fact]
    public void Empty_sentence()
    {
        Assert.False(Pangram.IsPangram(""));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Perfect_lower_case()
    {
        Assert.True(Pangram.IsPangram("abcdefghijklmnopqrstuvwxyz"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Only_lower_case()
    {
        Assert.True(Pangram.IsPangram("the quick brown fox jumps over the lazy dog"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Missing_the_letter_x()
    {
        Assert.False(Pangram.IsPangram("a quick movement of the enemy will jeopardize five gunboats"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Missing_the_letter_h()
    {
        Assert.False(Pangram.IsPangram("five boxing wizards jump quickly at it"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void With_underscores()
    {
        Assert.True(Pangram.IsPangram("the_quick_brown_fox_jumps_over_the_lazy_dog"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void With_numbers()
    {
        Assert.True(Pangram.IsPangram("the 1 quick brown fox jumps over the 2 lazy dogs"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Missing_letters_replaced_by_numbers()
    {
        Assert.False(Pangram.IsPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Mixed_case_and_punctuation()
    {
        Assert.True(Pangram.IsPangram("\"Five quacking Zephyrs jolt my wax bed.\""));
    }

    [Fact(Skip = "Remove this Skip property to run this test")]
    public void Case_insensitive()
    {
        Assert.False(Pangram.IsPangram("the quick brown fox jumps over with lazy FX"));
    }
}
using System.Collections.Generic;

public static class Pangram
{
    public static bool IsPangram(string s) =>
            new HashSet<char>(s.ToLower())
                .IsSupersetOf("abcdefghijklmnopqrstuvwxyz");
}

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?