exercism / problem-specifications

Shared metadata for exercism exercises.
MIT License
326 stars 541 forks source link

Implement new exercise, two-fer #757

Closed kytrinyx closed 7 years ago

kytrinyx commented 7 years ago

In #548 we discussed a new exercise which is equivalent to the current hello-world exercise (which conditionally provides a name, or defaults to "world") in the string "hello, %s".

The conclusion was to implement a new exercise, two-fer.

Next steps:

amit-rastogi commented 4 years ago

TwoferTest.scala throws a compilation error when running sbt test test("no name given") { Twofer.twofer() should be ("One for you, one for me.") } [error] Unspecified value parameter name. [error] Twofer.twofer() should be ("One for you, one for me.") [error] ^ [error] one error found [error] (Test / compileIncremental) Compilation failed

Twofer.twofer() has the name parameter missing. On adding an empty name parameter error is resolved.

test("no name given") { Twofer.twofer(name = "") should be ("One for you, one for me.") }

SaschaMann commented 4 years ago

@amit-rastogi you may want to report that in the scala track repo. You're more likely to find help there because this repo is about the shared test cases, not the scala implementation, and the scala team might not notice the bug report here.

(cc @exercism/scala)

heshamfm commented 4 years ago

I am not sure if this is the right place to call for help. I am new to Pharo and trying to use exercism.io to practice. However, I failed to import the example code that I downloaded from https://exercism.io/my/solutions/2c59b5cf2508431baae6a5b95c85a720 into Pharo. I checked in the community and came to understand that Pharo is using a file format called Tonel, which is not the one used in Pharo-exercism. In order to work on Pharo track exercises, one must take it into a Pharo image.

Please advise.

NobbZ commented 4 years ago

As far as I understand the workflow for Pharo, you need to use some prepared Pharo image that does the downloads and submissions for you.

Please refer to the Pharo instructions on the website and open a complete new issue at GitHub.com/exercism/exercism

heshamfm commented 4 years ago

@NobbZ I found this repo https://github.com/exercism/pharo-smalltalk but if i understand correctly, it is for already experienced Pharo developers to contribute. I could not find instructions for freshers like myself.

NobbZ commented 4 years ago

You can ask your question how to work with the pharo track there, chances to find someone who can help you are highest there.

Also, have you followed instructions from https://exercism.io/tracks/pharo-smalltalk/installation, which asks you to run some magic invocation to install the exercism plugin into the Pharo IDE?

IliasMariosG commented 4 years ago

Hello, in Python3 once I run the test by typing in pytest two_fer_test.py in my shell(zsh) the following is shown:

self = <two_fer_test.TwoFerTest testMethod=test_no_name_given>

    def test_no_name_given(self):
>       self.assertEqual(two_fer(), "One for you, one for me.")
E       TypeError: two_fer() missing 1 required positional argument: 'name'

two_fer_test.py:10: TypeError
======================================================================= short test summary info ========================================================================
FAILED two_fer_test.py::TwoFerTest::test_no_name_given - TypeError: two_fer() missing 1 required positional argument: 'name'

I am using pylint as well. It points to: > self.assertEqual(two_fer(), "One for you, one for me.")

If I add an empty name, thus: self.assertEqual(two_fer(""), "One for you, one for me.") it passes - given that I change the conditional statement accordingly in a separate code file named two_fer.py:

if name == " ":
    return "One for you, one for me"
coriolinus commented 4 years ago

@IliasMariosG This portion of the exercise is intended to teach you about default arguments. Almost certainly, your code is written something like

def two_fer(name):
    # implementation here

However, as the error says, this definition type only works if you pass a value which can be bound to the name parameter. The definition of the problem, however, asks that you define your two_fer function such that you can call it without a value. That would look more like this:

def two_fer(name = "default"):
    # implementation here

With that definition, anytime the caller doesn't provide a value to be bound to name, it will use the default value "default" instead. From there, it's pretty easy to get the test to pass.


Incidentally, while it's good that you've done your research to identify the source of the two-fer exercise, this isn't really the place to ask for help about the python track. Instead, you can create a new issue in exercism/python.

ElijahLynn commented 3 years ago

On a new checkout of this problem and running npm test I get the below error. I can run npm test fine on the Hello World exercise, fwiw.

❯ npm test

> @exercism/javascript@1.2.0 test /home/elijah/exercism/javascript/two-fer
> jest --no-cache ./*

sh: line 1: jest: command not found
npm ERR! Test failed.  See above for more details.

UPDATE: Okay, works fine, I forgot to run npm install!

erbase commented 3 years ago

I think there is a problem in the Delphi exercise on Git. It seems that the source of twofer.pas file is empty! Dows anyone know something about this?

NobbZ commented 3 years ago

Fill it with functionality. In the current v2, this is a choice some tracks did.

brownbonnie commented 2 years ago

As of Version 1.2.0, the unit tests for this exercise do not compile.

Compile error: Unspecified value parameters: name: String

The following line is missing en empty string: Twofer.twofer() should be ("One for you, one for me.")

It should be this instead: Twofer.twofer("") should be ("One for you, one for me.")

axor commented 2 years ago

Hello fellow developers.

I'm a total noob in python but I'm wondering why this code is not valid in your validation testing:

def two_fer(self=''):
    if self != '':
        return print(f'One for {self}, one for me.')
    else:
        return print('One for you, one for me.')

Thank you, and sorry in advance if this is not the correct channel to give you feedback regarding exercises.

ynfle commented 2 years ago

@axor there is a difference between returning a value and printing a value. return is intended to pass the value to the calling function, while print is intended to print the value to the console. If you remove the print function and the parentheses it should pass the tests.

Feel free to request mentoring (and if the tests isn't passing you can submit and incomplete solution from the CLI) and someone be able to assist you.

EDIT: issues for python specifically should be in https://github.com/exercism/python

fletheno1 commented 2 years ago

@axor there is a difference between returning a value and printing a value. return is intended to pass the value to the calling function, while print is intended to print the value to the console. If you remove the print function and the parentheses it should pass the tests.

Feel free to request mentoring (and if the tests isn't passing you can submit and incomplete solution from the CLI) and someone be able to assist you.

EDIT: issues for python specifically should be in https://github.com/exercism/python

!!! Good tip : try to return answer without print function, just compose the answer in combination with strings in parenthesis and the variable

saveriogzz commented 2 years ago

Hello! I'm trying to run the following scala code (which I reckon is correct)

object Twofer {
  def twofer(name: String = ""): String = name match {
    case "" => "One for you, one for me."
    case _  => s"One for $name, one for me."
  }
}

but I receive the following error when running the tests: image

glennj commented 2 years ago

@saveriogzz you'll get better response by creating an issue in the exercism/exercism repo

yuvakkrishnan commented 1 year ago

def two_fer(name=None): if name is not None: return "One for " + name + ", one for me." else: return "One for you, one for me."

print(two_fer("Alice"))

print(two_fer())

adithyabsk commented 1 year ago

This exercise may be out of order in the golang exercise listing page. I was surprised by the simplicity of the exercise until I came to this page to notice that it was supposed to be equivalent to hello world.

kytrinyx commented 1 year ago

@adithyabsk Would you report this in the forum? https://forum.exercism.org/ That will ensure that the right people see the discussion.

joanmarcriera commented 1 year ago

In mac , using brew I got the following error πŸ‘

Error: bats has been disabled because it has an archived upstream repository!

So I installed bats-core and it worked.

brew install bats-core
IsaacG commented 1 year ago

In mac , using brew I got the following error πŸ‘

Error: bats has been disabled because it has an archived upstream repository!

So I installed bats-core and it worked.

brew install bats-core

That's unrelated to this issue. For support, consider using the forum or Discord.