Git Product home page Git Product logo

gnu_smalltalk_koans's Introduction

GNU Smalltalk Koans Build Status

Hey there and welcome!

Supported GNU Smalltalk Versions

GNU Smalltalk versions 3.2.2 or higher should work on Mac OS X and Linux. I have written these koans on 3.2.2, Mac OS X 10.6.

Note: I am certain that 3.0.x does not work and it will complain about not understanding #asString.

GNU Smalltalk on Mac OS X

The simplest way to install GNU Smalltalk is via homebrew:

brew install gnu-smalltalk

Or you can use the Docker image. See below.

Running koans locally

In the root directory of the project, type:

script/run

You will see a message similar to this:

TestAssert#testTruth has damaged your karma.

This means you will need to open the TestAssert.st file under src/koans and solve the test under testTruth method (aka message).

All koan files contain a set of tests, each starting with 'test'. Solve each test one by one, running script/run in between.

By default, script/run does not reveal the answer. If you are truly stuck in a koan, type script/run_and_reveal to run and reveal the answer. Use this sparingly!

Running koans via Docker

Make sure you have Docker installed.

In the root directory of the project, type:

script/docker/run

This runs against a small image built on debian:stretch-slim.

Editors with Smalltalk support

  • vim
  • emacs

Things You Should Know Before Starting

| variable1 variable2 | is to declare variable1 and variable2 separate by a space. At least one space must be used to separate variables. Commas are not used.

:= is an assignment operator

"this is a comment"

'this is a string'

#speak is the notation used to describe the message 'speak'.

Words wrapped in <> are called pragmas and define class comments, category, imported namespaces, and the shape of indexed instance variables. More information here.

In depth information here.

Ok, have at it!

List of Koans

  • TestAssert
  • TestBasic
  • TestNil
  • TestObject
  • TestMessage
  • TestNumber
  • TestString
  • TestCharacter
  • TestSymbol
  • TestArray
  • TestOrderedCollection
  • TestSortedCollection
  • TestBag
  • TestAssociation
  • TestDictionary
  • TestSet
  • TestBlock
  • TestCollectionsRevisited
  • TestIteration
  • TestBoolean
  • TestException
  • TestRegex
  • TestClass

Future Koans

  • TestMetaclass

Pull Requests and Feedback are Welcome!

Please create a GitHub issue or find me on Twitter (@skim), if you have any suggestions on how to improve existing koans, new koans, or any other comments.

Inspiration and Credits

GNU Smalltalk Koans were inspired by Ruby Koans and Clojure Koans.

Thanks to Matt Yoho at Edgecase for letting me port some of the koans over.

Contributors

Other thanks:

License

cc-license

GNU Smalltalk Koans shares the same license as Ruby Koans and is released under a Creative Commons, Attribution-NonCommercial-ShareAlike, Version 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/) License.

gnu_smalltalk_koans's People

Contributors

igneus avatar mylesmegyesi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gnu_smalltalk_koans's Issues

Trouble with GNU Smalltalk Koan - testConstantArraysAreImmutable

In the koan testConstantArraysAreImmutable in TestArray.st, the test system seems quite happy to replace 'a' with 'd' in the immutable array #('a' 'b' 'c'). I cannot get this test to pass.

self expect: [ array at:1 put:'d' ] toRaise: SystemExceptions.ReadOnlyObject.

yields

Expected: SystemExceptions.ReadOnlyObject
Actual: 'd'

If I change the test to:

self expect: [ array at:1 put:'d'; yourself ] toRaise: SystemExceptions.ReadOnlyObject.

the results are:

Expected: SystemExceptions.ReadOnlyObject
Actual: ('d' 'b' 'c') (an instance of Array)

In both cases, array is assigned as follows:

array := #('a' 'b' 'c').

Further, when I perform the assignment using gst, I do get the expected exception:

st> array := #('a' 'b' 'c').
('a' 'b' 'c' )
st> array at:1 put:'d'.
Object: Array new: 3 "<0x7be038>" error: Invalid value nil: object is read-only
SystemExceptions.ReadOnlyObject(Exception)>>signal (ExcHandling.st:254)
SystemExceptions.ReadOnlyObject class(Exception class)>>signal (ExcHandling.st:151)
Array(Object)>>checkIndexableBounds:put: (Object.st:808)
Array(Object)>>at:put: (Object.st:875)
UndefinedObject>>executeStatements (a String:1)
nil

Rob Walsh

Flickering test failure

The TestClass#testMessageCollection test is flickering for me. Not sure if this is a problem with the my answers, something in this project, or gnu-smalltalk HEAD on OSX. Otherwise this is a nice introduction to smalltalk.

~/gnu_smalltalk_koans - [master●] » ./script/run
Loading package GNUSmalltalk

187 passed, 0 failed.

~/gnu_smalltalk_koans - [master●] » ./script/run
Loading package GNUSmalltalk

187 passed, 0 failed.

~/gnu_smalltalk_koans - [master●] » ./script/run
Loading package GNUSmalltalk

187 passed, 0 failed.

~/gnu_smalltalk_koans - [master●] » ./script/run
Loading package GNUSmalltalk

187 passed, 0 failed.

~/gnu_smalltalk_koans - [master●] » ./script/run
Loading package GNUSmalltalk

TestClass#testMessageCollection has damaged your karma.
(in src/koans/TestClass.st:69-70)

Heroes have no fears.  Expected value SHOULD equal actual value.

Expected : (#awesome #+ #say: ) (an instance of Array)
Actual   : (not revealed)


182 passed, 1 failed.
» for ((i=1;i<=100;i++)); do ./script/run | grep failed; done;
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
182 passed, 1 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
187 passed, 0 failed.
182 passed, 1 failed.
» uname -a
Darwin dev-mbp-gregg.local.tld 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64

In Test "testNilObjectCannotBeConvertedToString", can't find docs on what should be returned...

Rank Smalltalk beginner here, stepping through the test cases. I came across the test testNilObjectCannotBeConvertedToString, in file src/koans/TestObject.st.

How frustrating!

I have no idea what kind of Exception to put in here. I've tried a generic "Exception", but that doesn't work. I've tried googling for 'toRaise', about 'Exception' class, but still no luck.

Then I tried loading the repl:

GNU Smalltalk ready
st> [ nil asString ]
a BlockClosure

But nope...it's not a BlockClosure, or UndefinedObject.

Obviously the actual value is "not revealed", so I can't see what it should be.

Any suggestions on how to move forward here?

could you clarify one line in TestArray.st?

Hello, skim.

I'm halfway through your marvelous smalltalk riddles, and in TestArray.st in line #50 I found some discrepancy with actual results. In your koan:

self expect: [ Array with: 1 with: 3 with: 5 with: 7 with: 9 with: 11 ] toRaise: fillMeIn.

But when I execute this code in my gst interactive shell I get this:

st> [ Array with: 1 with: 3 with: 5 with: 7 with: 9 with: 11]
a BlockClosure
st>

So no exceptions of any kind are thrown.

My Smalltalk version:

gst -v
GNU Smalltalk version 3.2.2

Could you please clarify this issue?
Thank you.

could you please help me with an issue with OrderedCollection ?

It's me again) In TestOrderedCollection.st I always get this error (on line 23 I changed the boilerplate to #($a $b $c $d $e)):

orderedCollection := OrderedCollection with: $a with: $b with: $c with: $d with: $e.

self expect: #($a $b $c $d $e) toEqual: (orderedCollection).
(in src/koans/TestOrderedCollection.st:24-25)

Do not lose hope.  Expected value should equal actual value.

Expected : ($a $b $c $d $e ) (an instance of Array)
Actual   : (not revealed)

So it doesn't work. The only thing that makes it work is:

self expect: (OrderedCollection with: $a with: $b with: $c with: $d with: $e) toEqual: orderedCollection.

Is it the only way to pass this koan? I found nothing useful with google. Could you advise please?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.