move files from testing repo to this repo

This commit is contained in:
Michael Frank 2021-04-30 21:49:46 +12:00
parent fb304675d8
commit 35d7948aa2
17 changed files with 624 additions and 583 deletions

View File

@ -6,44 +6,15 @@ There will eventually be a suggested order of completion, but at this time since
2. Repeat String
3. Reverse String
## Setting Up
## How To Use These Exercises
Before you start you should have a few things installed on your machine:
1. NPM. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md).
2. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
3. Jest. Jest is a testing framework for JavaScript. To install it, navigate to your local copy of the repository and type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
2. Jest. Jest is a testing framework for JavaScript. To install it, type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
Once Jest has been installed, you should see a few additional files and folders appear in your repository:
* :file_folder: node_modules
* :page_facing_up: package-lock.json
* :page_facing_up: package.json
Open the `package.json` file in your text editor, and add the following code:
```json
"scripts": {
"test": "jest"
}
```
So that the end result looks something like this (don't worry if your jest version is different):
```json
{
"devDependencies": {
"jest": "^26.6.3"
}, <-- take note of the comma here
"scripts": {
"test": "jest"
}
}
```
That's it! Jest should be fully functional now. Onto the next section where we learn how to use it.
## How To Use These Exercises
Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'test.skip' compared to 'test'. This is purposeful. After you pass your first 'test', you will change the next 'test.skip' to an 'test' and test your code again. You'll do this until all conditions are satisfied.
**Note**: Due to the way Jest handles failed tests, it will return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
**Note**: Due to the way Jest handles failed tests, it will return an etest.skip code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
The first exercise, `helloWorld`, will walk you through the process in-depth.

View File

@ -1,4 +1,4 @@
const caesar = require('./caesar.js')
const caesar = require('./caesar')
test('works with single letters', () => {
expect(caesar('A', 1)).toBe('B');

View File

@ -1,7 +1,7 @@
let <%= title %> = require('./<%=title%>')
describe('<%=title%>', function() {
it('EDITME', function() {
test('EDITME', function() {
expect(<%=title%>()).toEqual(' ');
});

View File

@ -1140,7 +1140,7 @@
"dev": true,
"requires": {
"onetime": "^2.0.0",
"signal-exit": "^3.0.2"
"signal-etest.skip": "^3.0.2"
}
},
"string-width": {
@ -1271,9 +1271,9 @@
"merge": "^1.1.3"
}
},
"exit-hook": {
"etest.skip-hook": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-1.1.1.tgz",
"resolved": "https://registry.npmjs.org/etest.skip-hook/-/etest.skip-hook-1.1.1.tgz",
"integrity": "sha1-8FyiM7SMBdVP/wd2XfhQfpXAL/g="
},
"expand-brackets": {
@ -4225,7 +4225,7 @@
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
"requires": {
"exit-hook": "^1.0.0",
"etest.skip-hook": "^1.0.0",
"onetime": "^1.0.0"
}
},
@ -4373,9 +4373,9 @@
"integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==",
"dev": true
},
"signal-exit": {
"signal-etest.skip": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"resolved": "https://registry.npmjs.org/signal-etest.skip/-/signal-etest.skip-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true
},
@ -5515,7 +5515,7 @@
"dev": true,
"requires": {
"onetime": "^2.0.0",
"signal-exit": "^3.0.2"
"signal-etest.skip": "^3.0.2"
}
},
"string-width": {

View File

@ -13,14 +13,14 @@ Let's look at the spec file first:
const helloWorld = require('./helloWorld');
describe('Hello World', function() {
it('says hello world', function() {
test('says hello world', function() {
expect(helloWorld()).toEqual('Hello, World!');
});
});
```
At the very top of the file we use `require()` to import the code from the javascript file (`helloWorld.js`) so that we can test it.
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `it()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
The next block (`describe()`) is the body of the test. Basically, all it's doing is running your code and testing to see if the output is correct. The `test()` function describes what should be happening in plain english and then includes the `expect()` function. For this simple example it should be pretty simple to read.
For now you do not need to worry about how to write tests, but you should try to get comfortable enough with the syntax to figure out what the tests are asking you to do. Go ahead and run the tests by entering `jasmine helloWorld.spec.js` in the terminal and watch it fail. The output from that command should tell you exactly what went wrong with your code. In this case, running the `helloWorld()` function should return the phrase 'Hello, World!' but instead it returns an empty string...

983
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,9 @@
{
"devDependencies": {
"jest": "^26.6.3"
"jest": "^26.6.3",
"jest-cli": "^26.6.3"
},
"scripts": {
"test": "jest"
}
}
}

10
pigLatin/README.md Normal file
View File

@ -0,0 +1,10 @@
This exercise is tricky and was removed from our recommendations because it mostly leverages regular expressions for the solution, and those aren't really taught at this point in our curriculum.
Leaving it here for posterity, or a good challenge for anyone that wants to give it a shot.
Pig Latin is a children's language that is intended to be confusing when spoken quickly. Your job for this exercise is to create a solution that takes the words given and
turns them into pig latin. Please see the following wikipedia page for details regarding the rules of Pig Latin:
https://en.wikipedia.org/wiki/Pig_Latin
The rules section will give the rules and the examples that are required to complete this exercise.

5
pigLatin/pigLatin.js Normal file
View File

@ -0,0 +1,5 @@
const translate = function() {
// body...
}
module.exports = translate

56
pigLatin/pigLatin.spec.js Normal file
View File

@ -0,0 +1,56 @@
const pigLtain = require('./translate')
// Topics
// * modules
// * strings
// Pig Latin
// Pig Latin is a made-up children's language that's intended to be confusing. test obeys a few simple rules (below) but when test's spoken quickly test's really difficult for non-children (and non-native speakers) to understand.
// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.
// Rule 2: If a word begins with a consonant sound, move test to the end of the word, and then add an "ay" sound to the end of the word.
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
// See https://en.wikipedia.org/wiki/Pig_Latin for more details.
describe('translate', () => {
test('translates a word beginning with a vowel', () => {
expect(pigLatin.translate("apple")).toBe('appleay');
});
test.skip('translates a word beginning with a consonant', () => {
expect(pigLatin.translate("banana")).toBe("ananabay");
});
test.skip('translates a word beginning with two consonants', () => {
expect(pigLatin.translate("cherry")).toBe('errychay');
});
test.skip('translates two words', () => {
expect(pigLatin.translate("eat pie")).toBe('eatay iepay');
});
test.skip('translates a word beginning with three consonants', () => {
expect(pigLatin.translate("three")).toBe("eethray");
});
test.skip('counts "sch" as a single phoneme', () => {
expect(pigLatin.translate("school")).toBe("oolschay");
});
test.skip('counts "qu" as a single phoneme', () => {
expect(pigLatin.translate("quiet")).toBe("ietquay");
});
test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => {
expect(pigLatin.translate("square")).toBe("aresquay");
});
test.skip('translates many words', () => {
expect(pigLatin.translate("the quick brown fox")).toBe("ethay ickquay ownbray oxfay");
});
});

View File

@ -6,7 +6,7 @@ Write a function that simply repeats the string a given number of times:
repeatString('hey', 3) // returns 'heyheyhey'
```
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `x` in front of the `it()` function.
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `.skip` from the `test.skip()` function.
## Hints
@ -15,4 +15,4 @@ You will notice in this exercise that there are multiple tests (see in file `rep
- Create a variable to hold the string you're going to return, create a loop that repeats the given number of times and add the given string to the result on each loop.
- If running `jasmine repeatString.spec.js` raises `Temporarily disabled with xit` errors, make sure you have enabled the rest of the tests (see above).
- If running `jasmine repeatString.spec.js` raises `Temporarily disabled with test.skip` errors, make sure you have enabled the rest of the tests (see above).

View File

@ -1,22 +1,22 @@
const expect = require('expect');const repeatString = require('./repeatString')
const repeatString = require('./repeatString')
describe('repeatString', function() {
it('repeats the string', function() {
describe('repeatString', () => {
test('repeats the string', () => {
expect(repeatString('hey', 3)).toEqual('heyheyhey');
});
xit('repeats the string many times', function() {
test.skip('repeats the string many times', () => {
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
});
xit('repeats the string 1 times', function() {
test.skip('repeats the string 1 times', () => {
expect(repeatString('hey', 1)).toEqual('hey');
});
xit('repeats the string 0 times', function() {
test.skip('repeats the string 0 times', () => {
expect(repeatString('hey', 0)).toEqual('');
});
xit('returns ERROR with negative numbers', function() {
test.skip('returns ERROR with negative numbers', () => {
expect(repeatString('hey', -1)).toEqual('ERROR');
});
xit('repeats the string a random amount of times', function () {
test.skip('repeats the string a random amount of times', function () {
/*The number is generated by using Math.random to get a value from between
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
equals a number between 0 to 999 (this number will change everytime you run
@ -31,7 +31,7 @@ describe('repeatString', function() {
was randomaly generated. */
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
});
xit('works with blank strings', function() {
test.skip('works with blank strings', () => {
expect(repeatString('', 10)).toEqual('');
});
});

View File

@ -6,10 +6,7 @@ Pretty simple, write a function called `reverseString` that returns its input, r
reverseString('hello there') // returns 'ereht olleh'
```
You will notice in this exercise that there are multiple tests, after making the first one pass, enable the others one by one by deleting the `x` in front of the `it()` function.
You will notice in this exercise that there are multiple tests, after making the first one pass, enable the others one by one by deleting the `.skip` in front the `test.skip()` function.
## Hints
Strings in JavaScript cannot be reversed directly so you're going to have to split it into something else first.. do the reversal and then join it back together into a string.

View File

@ -1,18 +1,18 @@
const expect = require('expect');const reverseString = require('./reverseString')
const reverseString = require('./reverseString')
describe('reverseString', function() {
it('reverses single word', function() {
describe('reverseString', () => {
test('reverses single word', () => {
expect(reverseString('hello')).toEqual('olleh');
});
xit('reverses multiple words', function() {
test.skip('reverses multiple words', () => {
expect(reverseString('hello there')).toEqual('ereht olleh')
})
xit('works with numbers and punctuation', function() {
test.skip('works with numbers and punctuation', () => {
expect(reverseString('123! abc!')).toEqual('!cba !321')
})
xit('works with blank strings', function() {
test.skip('works with blank strings', () => {
expect(reverseString('')).toEqual('')
})
});

View File

@ -1,22 +1,22 @@
const expect = require('expect');const snakeCase = require('./snakeCase')
const snakeCase = require('./snakeCase')
describe('snakeCase', function() {
it('works with simple lowercased phrases', function() {
describe('snakeCase', () => {
test('works with simple lowercased phrases', () => {
expect(snakeCase('hello world')).toEqual('hello_world');
});
xit('works with Caps and punctuation', function() {
test.skip('works with Caps and punctuation', () => {
expect(snakeCase('Hello, World???')).toEqual('hello_world');
});
xit('works with longer phrases', function() {
test.skip('works with longer phrases', () => {
expect(snakeCase('This is the song that never ends....')).toEqual('this_is_the_song_that_never_ends');
});
xit('works with camel case', function() {
test.skip('works with camel case', () => {
expect(snakeCase('snakeCase')).toEqual('snake_case');
});
xit('works with kebab case', function() {
test.skip('works with kebab case', () => {
expect(snakeCase('snake-case')).toEqual('snake_case');
});
xit('works with WTF case', function() {
test.skip('works with WTF case', () => {
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome');
});

View File

@ -1,22 +1,22 @@
const expect = require('expect');const sumAll = require('./sumAll')
const sumAll = require('./sumAll')
describe('sumAll', function() {
it('sums numbers within the range', function() {
describe('sumAll', () => {
test('sums numbers within the range', () => {
expect(sumAll(1, 4)).toEqual(10);
});
xit('works with large numbers', function() {
test.skip('works with large numbers', () => {
expect(sumAll(1, 4000)).toEqual(8002000);
});
xit('works with larger number first', function() {
test.skip('works with larger number first', () => {
expect(sumAll(123, 1)).toEqual(7626);
});
xit('returns ERROR with negative numbers', function() {
test.skip('returns ERROR with negative numbers', () => {
expect(sumAll(-10, 4)).toEqual('ERROR');
});
xit('returns ERROR with non-number parameters', function() {
test.skip('returns ERROR with non-number parameters', () => {
expect(sumAll(10, "90")).toEqual('ERROR');
});
xit('returns ERROR with non-number parameters', function() {
test.skip('returns ERROR with non-number parameters', () => {
expect(sumAll(10, [90, 1])).toEqual('ERROR');
});
});

View File

@ -1,25 +1,25 @@
const expect = require('expect');const {ftoc, ctof} = require('./tempConversion')
const {ftoc, ctof} = require('./tempConversion')
describe('ftoc', function() {
it('works', function() {
describe('ftoc', () => {
test('works', () => {
expect(ftoc(32)).toEqual(0);
});
xit('rounds to 1 decimal', function() {
test.skip('rounds to 1 decimal', () => {
expect(ftoc(100)).toEqual(37.8);
});
xit('works with negatives', function() {
test.skip('works with negatives', () => {
expect(ftoc(-100)).toEqual(-73.3);
});
});
describe('ctof', function() {
xit('works', function() {
describe('ctof', () => {
test.skip('works', () => {
expect(ctof(0)).toEqual(32);
});
xit('rounds to 1 decimal', function() {
test.skip('rounds to 1 decimal', () => {
expect(ctof(73.2)).toEqual(163.8);
});
xit('works with negatives', function() {
test.skip('works with negatives', () => {
expect(ctof(-10)).toEqual(14);
});
});