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

katrinleinweber's solution

to Pangram in the R Track

Published at Jul 13 2018 · 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.

Installation

See this guide for instructions on how to setup your local R environment.

How to implement your solution

In each problem folder, there is a file named <exercise_name>.R containing a function that returns a NULL value. Place your implementation inside the body of the function.

How to run tests

Inside of RStudio, simply execute the test_<exercise_name>.R script. This can be conveniently done with testthat's auto_test function. Because exercism code and tests are in the same folder, use this same path for both code_path and test_path parameters. On the command-line, you can also run Rscript test_<exercise_name>.R.

Source

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

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

test_pangram.R

source("./pangram.R")
library(testthat)

context("pangram")

test_that("sentence empty", {
    expect_false(is_pangram(""))
})

test_that("pangram with only lower case", {
    expect_true(is_pangram("the quick brown fox jumps over the lazy dog"))
})

test_that("missing character 'x'", {
    expect_false(
      is_pangram("a quick movement of the enemy will jeopardize five gunboats"))
})

test_that("another missing character 'x'", {
    expect_false(is_pangram("the quick brown fish jumps over the lazy dog"))
})

test_that("pangram with underscores", {
    expect_true(is_pangram("the_quick_brown_fox_jumps_over_the_lazy_dog"))
})

test_that("pangram with numbers", {
    expect_true(is_pangram("the 1 quick brown fox jumps over the 2 lazy dogs"))
})

test_that("missing letters replaced by numbers", {
    expect_false(is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"))
})

test_that("pangram with mixed case and punctuation", {
    expect_true(is_pangram("\"Five quacking Zephyrs jolt my wax bed.\""))
})

test_that("upper and lower case versions of the same character should not be 
          counted separately", {
    expect_false(is_pangram("the quick brown fox jumped over the lazy FOX"))
})

message("All tests passed for exercise: pangram")
is_pangram <- function(input) {

}

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?