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

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews