-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add concept exercise test with type tests (#74)
- Loading branch information
1 parent
62f30a3
commit 9231c48
Showing
26 changed files
with
746 additions
and
15 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
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,16 @@ | ||
import { join } from 'node:path' | ||
import shelljs from 'shelljs' | ||
import { assertPass } from './asserts.mjs' | ||
import { fixtures } from './paths.mjs' | ||
|
||
// run this file like: | ||
// corepack yarn dlx cross-env SILENT=0 corepack yarn node test/dev.test.mjs | ||
|
||
shelljs.echo( | ||
'typescript-test-runner > passing solution (jest + tstyche) > no output directory' | ||
) | ||
assertPass( | ||
'lasagna', | ||
join(fixtures, 'lasagna', 'pass'), | ||
join(fixtures, 'lasagna', 'pass') | ||
) |
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,30 @@ | ||
# Hints | ||
|
||
## 1. Define the expected oven time in minutes | ||
|
||
- Define a [constant][constants] which should contain the [`number`][numbers] value specified in the recipe. | ||
- [`export`][export] the constant. | ||
|
||
## 2. Calculate the remaining oven time in minutes | ||
|
||
- [Explicitly return a number][return] from the function. | ||
- Use the [mathematical operator for subtraction][operators] to subtract values. | ||
|
||
## 3. Calculate the preparation time in minutes | ||
|
||
- [Explicitly return a number][return] from the function. | ||
- Use the [mathematical operator for multiplication][operators] to multiply values. | ||
- Use the extra constant for the time in minutes per layer. | ||
|
||
## 4. Calculate the total working time in minutes | ||
|
||
- [Explicitly return a number][return] from the function. | ||
- [Invoke][invocation] one of the other methods implemented previously. | ||
- Use the [mathematical operator for addition][operators] to add values. | ||
|
||
[return]: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Return_values | ||
[export]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export | ||
[operators]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
[constants]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const | ||
[invocation]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions#Calling_functions | ||
[numbers]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type |
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,38 @@ | ||
# Instructions | ||
|
||
Lucian's girlfriend is on her way home, and he hasn't cooked their anniversary dinner! | ||
|
||
In this exercise, you're going to write some code to help Lucian cook an exquisite lasagna from his favorite cookbook. | ||
|
||
You have four tasks related to the time spent cooking the lasagna. | ||
|
||
## 1. Define the expected oven time in minutes | ||
|
||
Define the `EXPECTED_MINUTES_IN_OVEN` constant that represents how many minutes the lasagna should be in the oven. It must be exported. According to the cooking book, the expected oven time in minutes is `40`. | ||
|
||
## 2. Calculate the remaining oven time in minutes | ||
|
||
Implement the `remainingMinutesInOven` function that takes the actual minutes the lasagna has been in the oven as a _parameter_ and _returns_ how many minutes the lasagna still has to remain in the oven, based on the **expected oven time in minutes** from the previous task. | ||
|
||
```javascript | ||
remainingMinutesInOven(30) | ||
// => 10 | ||
``` | ||
|
||
## 3. Calculate the preparation time in minutes | ||
|
||
Implement the `preparationTimeInMinutes` function that takes the number of layers you added to the lasagna as a _parameter_ and _returns_ how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare. | ||
|
||
```javascript | ||
preparationTimeInMinutes(2) | ||
// => 4 | ||
``` | ||
|
||
## 4. Calculate the total working time in minutes | ||
|
||
Implement the `totalTimeInMinutes` function that takes _two parameters_: the `numberOfLayers` parameter is the number of layers you added to the lasagna, and the `actualMinutesInOven` parameter is the number of minutes the lasagna has been in the oven. The function should _return_ how many minutes in total you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment. | ||
|
||
```javascript | ||
totalTimeInMinutes(3, 20) | ||
// => 26 | ||
``` |
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,71 @@ | ||
# Introduction | ||
|
||
JavaScript is a dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles. | ||
|
||
## (Re-)Assignment | ||
|
||
There are a few primary ways to assign values to names in JavaScript - using variables or constants. On Exercism, variables are always written in [camelCase][wiki-camel-case]; constants are written in [SCREAMING_SNAKE_CASE][wiki-snake-case]. There is no official guide to follow, and various companies and organizations have various style guides. _Feel free to write variables any way you like_. The upside from writing them the way the exercises are prepared is that they'll be highlighted differently in the web interface and most IDEs. | ||
|
||
Variables in JavaScript can be defined using the [`const`][mdn-const], [`let`][mdn-let] or [`var`][mdn-var] keyword. | ||
|
||
A variable can reference different values over its lifetime when using `let` or `var`. For example, `myFirstVariable` can be defined and redefined many times using the assignment operator `=`: | ||
|
||
```javascript | ||
let myFirstVariable = 1 | ||
myFirstVariable = 'Some string' | ||
myFirstVariable = new SomeComplexClass() | ||
``` | ||
|
||
In contrast to `let` and `var`, variables that are defined with `const` can only be assigned once. This is used to define constants in JavaScript. | ||
|
||
```javascript | ||
const MY_FIRST_CONSTANT = 10 | ||
|
||
// Can not be re-assigned. | ||
MY_FIRST_CONSTANT = 20 | ||
// => TypeError: Assignment to constant variable. | ||
``` | ||
|
||
> 💡 In a later Concept Exercise the difference between _constant_ assignment / binding and _constant_ value is explored and explained. | ||
## Function Declarations | ||
|
||
In JavaScript, units of functionality are encapsulated in _functions_, usually grouping functions together in the same file if they belong together. These functions can take parameters (arguments), and can _return_ a value using the `return` keyword. Functions are invoked using `()` syntax. | ||
|
||
```javascript | ||
function add(num1, num2) { | ||
return num1 + num2 | ||
} | ||
|
||
add(1, 3) | ||
// => 4 | ||
``` | ||
|
||
> 💡 In JavaScript there are _many_ different ways to declare a function. These other ways look different than using the `function` keyword. The track tries to gradually introduce them, but if you already know about them, feel free to use any of them. In most cases, using one or the other isn't better or worse. | ||
## Exposing to Other Files | ||
|
||
To make a `function`, a constant, or a variable available in _other files_, they need to be [exported][mdn-export] using the `export` keyword. Another file may then [import][mdn-import] these using the `import` keyword. This is also known as the module system. A great example is how all the tests work. Each exercise has at least one file, for example `lasagna.js`, which contains the _implementation_. Additionally there is at least one other file, for example `lasagna.spec.js`, that contains the _tests_. This file _imports_ the public (i.e. exported) entities in order to test the implementation: | ||
|
||
```javascript | ||
// file.js | ||
export const MY_VALUE = 10 | ||
|
||
export function add(num1, num2) { | ||
return num1 + num2 | ||
} | ||
|
||
// file.spec.js | ||
import { MY_VALUE, add } from './file' | ||
|
||
add(MY_VALUE, 5) | ||
// => 15 | ||
``` | ||
|
||
[mdn-const]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const | ||
[mdn-export]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export | ||
[mdn-import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import | ||
[mdn-let]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let | ||
[mdn-var]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var | ||
[wiki-camel-case]: https://en.wikipedia.org/wiki/Camel_case | ||
[wiki-snake-case]: https://en.wikipedia.org/wiki/Snake_case |
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 @@ | ||
{ | ||
"authors": ["SleeplessByte"], | ||
"files": { | ||
"solution": [ | ||
"lasagna.ts" | ||
], | ||
"test": [ | ||
"__typetests__/lasagna.tst.ts", | ||
"lasagna.test.ts" | ||
], | ||
"exemplar": [ | ||
".meta/exemplar.ts" | ||
] | ||
}, | ||
"forked_from": [ | ||
"javascript/lasagna" | ||
], | ||
"blurb": "Learn the basics of TypeScript cooking a brilliant lasagna from your favorite cooking book.", | ||
"custom": { | ||
"version.tests.compatibility": "jest-29", | ||
"flag.tests.task-per-describe": true, | ||
"flag.tests.may-run-long": false, | ||
"flag.tests.includes-optional": false, | ||
"flag.tests.jest": true, | ||
"flag.tests.tstyche": true | ||
} | ||
} |
Oops, something went wrong.