wolfiton

wolfiton

I was going though the exercises in http://elixirkoans.io and stumbled upon something odd. even if my code does solve the problem i don’t get a pass.

Exercise:

koan "Be careful, a message may be altered" do
    assert String.replace("An awful day", "awful", "incredible") == String.replace("awful","awful","incredible", global: true)
  end

Console response

Be careful, a message may be altered
Assertion failed in lib/koans/02_strings.ex:23
assert(String.replace("An awful day", "awful", "incredible") == String.replace("awful", "awful", "incredible", global: true))

left:  "An incredible day"
right: "incredible"

The answers they expect can be seen here elixir-koans/test/koans/strings_koan_test.exs at master · elixirkoans/elixir-koans · GitHub and i think is the same thing I am providing.
So why doesn’t my answer get a successful pass?

Thanks

Showing Posts 1 to 3

NobbZ

NobbZ

Sorry, I don’t get it… Also I do not see any relationship between the code you show here and the code you linked…

I have to say though that I never did the koans beyond a certain point… Its not a way for me to learn…

But what I can tell is, that you create 2 strings "An incredible day" and "incredible" and assert for equality. As you clearly can see, those are not equal…

wolfiton

wolfiton OP

This is the full file and I get the pass after each exercise except this one

defmodule Strings do
  use Koans

  @intro "Strings"

  koan "Strings are there to represent text" do
    assert "hello" == "hello"
  end

  koan "Values may be inserted into strings by interpolation" do
    assert "1 + 1 = #{1 + 1}" == "1 + 1 = #{1 + 1}"
  end

  koan "They can be put together" do
    assert "hello world" == "hello" <> " " <> "world"
  end

  koan "Or pulled apart into a list when needed" do
    assert ["hello", "world"] == String.split("hello world", " ")
  end

  koan "Be careful, a message may be altered" do
    assert String.replace("An awful day", "awful", "incredible") == String.replace("awful","awful","incredible", global: true)
  end

  koan "But strings never lie about themselves" do
    assert true == String.contains?("An incredible day", "day")
  end

  koan "Sometimes you want just the opposite of what is given" do
    assert "banana" == String.reverse("ananab")
  end

  koan "Other times a little cleaning is in order" do
    assert String.trim("  \n banana\n  ") == "banana"
  end

  koan "Repetition is the mother of learning" do
    assert String.duplicate("String", 3) == "StringStringString"
  end

  koan "Strings can be louder when necessary" do
    assert String.upcase("listen") == "LISTEN"
  end
end

wolfiton

wolfiton OP

Got it! It wanted only the String version of the assertion, in this case “An incredible day”

— All posts loaded —

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews