-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add two-fer exercise * Undo VSCode reformatting of config.json * Remove default value from TwoFer.cfc
- Loading branch information
Showing
12 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Instructions | ||
|
||
Your task is to determine what you will say as you give away the extra cookie. | ||
|
||
If your friend likes cookies, and is named Do-yun, then you will say: | ||
|
||
```text | ||
One for Do-yun, one for me. | ||
``` | ||
|
||
If your friend doesn't like cookies, you give the cookie to the next person in line at the bakery. | ||
Since you don't know their name, you will say _you_ instead. | ||
|
||
```text | ||
One for you, one for me. | ||
``` | ||
|
||
Here are some examples: | ||
|
||
| Name | Dialogue | | ||
| :----- | :-------------------------- | | ||
| Alice | One for Alice, one for me. | | ||
| Bohdan | One for Bohdan, one for me. | | ||
| | One for you, one for me. | | ||
| Zaphod | One for Zaphod, one for me. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Introduction | ||
|
||
In some English accents, when you say "two for" quickly, it sounds like "two fer". | ||
Two-for-one is a way of saying that if you buy one, you also get one for free. | ||
So the phrase "two-fer" often implies a two-for-one offer. | ||
|
||
Imagine a bakery that has a holiday offer where you can buy two cookies for the price of one ("two-fer one!"). | ||
You go for the offer and (very generously) decide to give the extra cookie to a friend. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Your implementation of the TwoFer exercise | ||
*/ | ||
component { | ||
|
||
/** | ||
* @returns | ||
*/ | ||
function twoFer( name="you" ) { | ||
return "One for " & name & ", one for me." | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
component extends="TwoFerTest" { | ||
|
||
function beforeAll(){ | ||
SUT = createObject( 'Solution' ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"authors": [ | ||
"BNAndras" | ||
], | ||
"files": { | ||
"solution": [ | ||
"TwoFer.cfc" | ||
], | ||
"test": [ | ||
"TwoFerTest.cfc" | ||
], | ||
"example": [ | ||
".meta/Example.cfc", | ||
".meta/ExampleTest.cfc" | ||
] | ||
}, | ||
"blurb": "Create a sentence of the form \"One for X, one for me.\".", | ||
"source_url": "https://github.com/exercism/problem-specifications/issues/757" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[1cf3e15a-a3d7-4a87-aeb3-ba1b43bc8dce] | ||
description = "no name given" | ||
|
||
[b4c6dbb8-b4fb-42c2-bafd-10785abe7709] | ||
description = "a name given" | ||
|
||
[3549048d-1a6e-4653-9a79-b0bda163e8d5] | ||
description = "another name given" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* I am a CommandBox task runner which you can use to test your implementation of this exercise against the | ||
* provided test suite. To use me, open the CommandBox CLI and run this: | ||
* | ||
* CommandBox> task run TestRunner | ||
* | ||
* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this: | ||
* | ||
* CommandBox> task run TestRunner --watcher | ||
* | ||
*/ | ||
component { | ||
|
||
/** | ||
* @solution Runs the tests against the solution | ||
* @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop | ||
*/ | ||
function run( boolean solution=false, boolean watcher=false ) { | ||
|
||
ensureTestBox(); | ||
|
||
if( watcher ) { | ||
|
||
// Tabula rasa | ||
command( 'cls' ).run(); | ||
|
||
// Start watcher | ||
watch() | ||
.paths( '*.cfc' ) | ||
.inDirectory( getCWD() ) | ||
.withDelay( 500 ) | ||
.onChange( function() { | ||
|
||
// Clear the screen | ||
command( 'cls' ) | ||
.run(); | ||
|
||
// This is neccessary so changes to tests get picked up right away. | ||
pagePoolClear(); | ||
|
||
runTests( solution ); | ||
|
||
} ) | ||
.start(); | ||
|
||
} else { | ||
runTests( solution ); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Make sure the TestBox framework is installed | ||
*/ | ||
private function ensureTestBox() { | ||
var excerciseRoot = getCWD(); | ||
var testBoxRoot = excerciseRoot & '/testbox'; | ||
|
||
if( !directoryExists( testBoxRoot ) ) { | ||
|
||
print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole(); | ||
command( 'install' ) | ||
.inWorkingDirectory( excerciseRoot ) | ||
.run(); | ||
} | ||
|
||
// Bootstrap TestBox framework | ||
filesystemUtil.createMapping( '/testbox', testBoxRoot ); | ||
} | ||
|
||
/** | ||
* Invoke TestBox to run the test suite | ||
*/ | ||
private function runTests( boolean solution=false ) { | ||
|
||
// Create TestBox and run the tests | ||
testData = new testbox.system.TestBox() | ||
.runRaw( directory = { | ||
// Find all CFCs... | ||
mapping = filesystemUtil.makePathRelative( getCWD() ), | ||
// ... in this directory ... | ||
recurse = false, | ||
// ... whose name ends in "test" | ||
filter = function( path ) { | ||
return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' ); | ||
} | ||
} ) | ||
.getMemento(); | ||
|
||
// Print out the results with ANSI formatting for the CLI | ||
getInstance( 'CLIRenderer@testbox-commands' ) | ||
.render( print, testData, true ); | ||
|
||
print.toConsole(); | ||
|
||
// Set proper exit code | ||
if( testData.totalFail || testData.totalError ) { | ||
setExitCode( 1 ); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Your implementation of the TwoFer exercise | ||
*/ | ||
component { | ||
|
||
/** | ||
* @returns | ||
*/ | ||
function twoFer( name ) { | ||
// Implement me here | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
component extends="testbox.system.BaseSpec" { | ||
|
||
function beforeAll(){ | ||
SUT = createObject( 'TwoFer' ); | ||
} | ||
|
||
function run(){ | ||
|
||
describe( "My TwoFer class", function(){ | ||
|
||
it( 'no name given', function(){ | ||
expect( SUT.twoFer() ).toBe( 'One for you, one for me.' ); | ||
}); | ||
|
||
it( 'a name given', function(){ | ||
expect( SUT.twoFer( name='Alice' ) ).toBe( 'One for Alice, one for me.' ); | ||
}); | ||
|
||
it( 'another name given', function(){ | ||
expect( SUT.twoFer( name='Bob' ) ).toBe( 'One for Bob, one for me.' ); | ||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies":{ | ||
"testbox":"^2.5.0+107" | ||
}, | ||
"installPaths":{ | ||
"testbox":"testbox/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!--- | ||
This file will only be used if you want to start up a web server in this directory. You can do so by running: | ||
$> box | ||
CommandBox> install | ||
CommandBox> server start | ||
However, this is not necessary unless you really just want to use the HTML reporters on TestBox. | ||
Ideally, you'll skip the need for this file entirely and just run the tests directly frm the CLI like this: | ||
CommandBox> task run TestRunner | ||
---> | ||
<cfsetting showDebugOutput="false"> | ||
<cfparam name="url.reporter" default="simple"> | ||
<cfscript> | ||
// get a list of all CFCs in this folder whose name looks like "XXXTest.cfc" | ||
// And turn it into compnent path relative to the web root | ||
url.bundles = directoryList( | ||
path=expandPath( '/' ), | ||
filter='*Test.cfc' ) | ||
.map( function( path ) { | ||
return path | ||
.replaceNoCase( expandPath( '/' ), '' ) | ||
.left( -4 ) | ||
} ) | ||
.toList(); | ||
</cfscript> | ||
<!--- Ensure TestBox ---> | ||
<cfif fileExists( "/testbox/system/runners/HTMLRunner.cfm" )> | ||
<!--- Include the TestBox HTML Runner ---> | ||
<cfinclude template="/testbox/system/runners/HTMLRunner.cfm"> | ||
<cfelse> | ||
Oops, you don't have TestBox installed yet! Please run <b>box install</b> from the root of your excercise folder and refresh this page. | ||
</cfif> |