These are the elements used inside Ellie to build an exercise.
If the exercise require The Elm Architecure and tests need to access the Model, it is possible to use exerciseWithTea instead of the simpler exercise. It is the analogue of Browser.element but without flags.
import Exercises exposing (..)
-- Write a function `last` that returns
-- the last element of a list.
--
last : List a -> Maybe a
last xs =
-- Your implementation goes here
Nothing
main : Program Flags (Model ModelExercise) (Msg MsgExercise)
main =
exerciseWithTea
{ tests =
-- Your implementation should pass
-- these tests
\model ->
[ last [ 1, 2, 3, 4 ] == Just 4
, last [ 1 ] == Just 1
, last [] == Nothing
, last [ 'a', 'b', 'c' ] == Just 'c'
]
, init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- Following the definitions of
-- init, view, update, and subscriptions.Flags are used to pass details about the exercises to the page.
They can be either loaded from external scripts, like in this example:
(HTML)
<script src="https://elm-exercises.netlify.app/js/index.js"></script>
<script src="https://elm-exercises.netlify.app/js/001.js"></script>
<script src="https://elm-exercises.netlify.app/start.js"></script>You can check the forrmat of the data in these files as reference:
Or they can be hard coded, like in this example (See ExerciseData for a detailed explanation of the fields):
(JavaScript)
var app = Elm.Main.init({
node: document.getElementById("elm"),
flags: {
index: JSON.stringify([]),
exercise: JSON.stringify(
{ id: 1 // Exercise ID
, title: "" // Title of the exercise
, difficulty: Easy // Easy | Medium | Hard | Undefined
, problem: "" // Details of the problem to be solved
, tests: [] // List of tests
, hints: [] // List of hints
, solutions: [] // List of solutions
, ellie: "" // Ellie ID
}
)
}
});Internal. Exposed to be used in type signatures
Internal. Exposed to be used in type signatures
These are the same tests of elm-explorations/test. Refer to that package for the documentation.
Rename Expectation to Test as they can be run immediately in this context