Skip to content

Commit

Permalink
Fixed ExercismGeneratorTest for P11, P12.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajger committed Feb 16, 2024
1 parent ec2fac5 commit 85a6003
Showing 1 changed file with 33 additions and 121 deletions.
154 changes: 33 additions & 121 deletions dev/src/ExercismTests/ExercismGeneratorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ self activeExercisesWithPackageDo: [:exPackage |
{ #category : #asserting }
ExercismGeneratorTest >> assertExerciseTests [

| file |
| file exerciseSourceCode|
file := memoryFileReference / 'two-fer' / 'TwoFerTest.class.st'.

self assert: file exists.
exerciseSourceCode := file contents withLineEndings: lineEnding.
"test just for important substrings - entire file is Tonel version dependent."
self expectedTwoFerTestContentsSubstrings do: [:testedString |
self assert: (exerciseSourceCode includesSubstring: testedString)
].

self
assert: (file contents withLineEndings: lineEnding)
equals: (self expectedTwoFerTestContents withLineEndings: lineEnding)
shouldnt: [ TonelParser parseString: exerciseSourceCode ]
raise: TonelParseError
description: 'Parsing of souce code of Exercism test should not raise parsing exception and definition can be loaded.'.
]

{ #category : #asserting }
Expand All @@ -87,13 +94,20 @@ ExercismGeneratorTest >> assertHints [
{ #category : #asserting }
ExercismGeneratorTest >> assertSolution [

| file |
| file exerciseSourceCode|
file := memoryFileReference / 'two-fer' / '.meta' / 'solution' / 'TwoFer.class.st'.

self assert: file exists.
exerciseSourceCode := file contents withLineEndings: lineEnding.
"test just for important substrings - entire file is Tonel version dependent."
self expectedTwoFerSolutionContentsSubstrings do: [:testedString |
self assert: (exerciseSourceCode includesSubstring: testedString)
].

self
assert: (file contents withLineEndings: lineEnding)
equals: (self expectedTwoFerSolutionContents withLineEndings: lineEnding)
shouldnt: [ TonelParser parseString: exerciseSourceCode ]
raise: TonelParseError
description: 'Parsing of souce code of Exercism solution should not raise parsing exception and definition can be loaded.'.
]

{ #category : #private }
Expand All @@ -107,128 +121,26 @@ There is also a third type of method, binary, which takes only 1 parameter and u
]

{ #category : #private }
ExercismGeneratorTest >> expectedTwoFerSolutionContents [

^ '"
This is a sample solution for Exercism students.
Of interest, in this example is that classes can define instance methods with the same name, but taking different numbers of parameters.
ExercismGeneratorTest >> expectedTwoFerSolutionContentsSubstrings [

"
Class {
#name : #TwoFer,
#superclass : #Object,
#category : #''Exercise@TwoFer''
}
{ #category : #example }
TwoFer >> who [
^ Array
with: ('TwoFer >> who [
^ ''One for you, one for me.''
]
{ #category : #example }
TwoFer >> who: aString [
]' withLineEndings: lineEnding)
with: ('TwoFer >> who: aString [
^ ''One for '', aString, '', one for me.''
]
'
]

{ #category : #private }
ExercismGeneratorTest >> expectedTwoFerTestContents [

^ '"
# Two Fer
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
Given a name, return a string with the message:
```text
One for X, one for me.
```
Where X is the given name.
However, if the name is missing, return the string:
```text
One for you, one for me.
```
Here are some examples:
|Name | String to return
|:------:|:-----------------:
|Alice | One for Alice, one for me.
|Bob | One for Bob, one for me.
| | One for you, one for me.
|Zaphod | One for Zaphod, one for me.
## Hint
]' withLineEndings: lineEnding)

In Pharo, classes are objects that can have instance and class methods, however unlike HelloWorld the tests for TwoFer have been written to call instance methods. Typically class methods are used for constructing new objects (like a contructor in other languages).
While referring to methods, its useful to know that a method which has no parameters, is called a unary method, and a method taking multiple parameters, each deliniated by a word ending with a '':'', is called a keyword method.
There is also a third type of method, binary, which takes only 1 parameter and uses a symbol(s) for a name (typically a mathematical one like: +, -, & etc).
"
Class {
#name : #TwoFerTest,
#superclass : #ExercismTest,
#instVars : [
''twoFer''
],
#category : #''Exercise@TwoFer''
}
{ #category : #config }
TwoFerTest class >> exercise [
"Answer the configured exercise meta data for this exercise, an ExercismExercise"
^(self createExerciseAfter: HelloWorldTest)
isCore: true;
difficulty: 1;
topics: #(''strings'' ''text-formatting'' ''refactoring'');
yourself
]

{ #category : #config }
TwoFerTest class >> uuid [
"Answer a unique id for this exercise"
^''9806fcc0-8505-4012-bd64-3f7468014df5''
]
{ #category : #config }
TwoFerTest class >> version [
"Answer the exercise version number string this test was derived from"
^''1.2.0''
]
{ #category : #running }
TwoFerTest >> setUp [
super setUp.
twoFer := TwoFer new.
]
{ #category : #tests }
TwoFerTest >> testANameGiven [
self assert: (twoFer who: ''Alice'') equals: ''One for Alice, one for me.''
]
{ #category : #tests }
TwoFerTest >> testAnotherNameGiven [
self assert: (twoFer who: ''Bob'') equals: ''One for Bob, one for me.''
]
{ #category : #private }
ExercismGeneratorTest >> expectedTwoFerTestContentsSubstrings [

{ #category : #tests }
TwoFerTest >> testNoNameGiven [
self assert: twoFer who equals: ''One for you, one for me.''
]
'
^ Array
with: 'Two Fer'
with: 'Class'
with: 'TwoFerTest'
with: 'ExercismTest'
]

{ #category : #running }
Expand Down

0 comments on commit 85a6003

Please sign in to comment.