Commit 2e443d8a authored by Jakob Moser's avatar Jakob Moser
Browse files

Add type hints, rename parameter

parent 03d1aa58
Loading
Loading
Loading
Loading
+29 −18
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
import { getTerminalContents, runCommand } from "./jslinux.api.mjs"
import { arrayEquals } from "./util.mjs"
import { getHandInToken } from "./snakeoil.mjs"
import { State } from "./state.mjs"

/**
 * An exercise. It has a human-readable name and an `execute` function
@@ -68,30 +69,34 @@ class Exercise {

    /**
     * Get if the exercise is solved in the given current state
     * @param {State} state The current state
     */
    isSolved(currentState) {
        return currentState.solvedExercises.includes(this.index)
    isSolved(state) {
        return state.solvedExercises.includes(this.index)
    }

    /**
     * Get if the exercise is current in the given current state
     * @param {State} state The current state
     */
    isCurrent(currentState) {
        return currentState.exerciseIndex === this.index
    isCurrent(state) {
        return state.exerciseIndex === this.index
    }

    /**
     * Marks this exercise as solved, modifying the given current state
     * @param {State} state The current state
     */
    markAsSolved(currentState) {
        currentState.markAsSolved(this.index)
    markAsSolved(state) {
        state.markAsSolved(this.index)
    }

    /**
     * Marks this exercise as current, modifying the given current state
     * @param {State} state The current state
     */
    markAsCurrent(currentState) {
        currentState.exerciseIndex = this.index
    markAsCurrent(state) {
        state.exerciseIndex = this.index
    }
}

@@ -127,6 +132,8 @@ class ExerciseExecutionContext {
     * By default, after running the provided command, "clear" is
     * executed to clear the terminal. If you do not want to clear the
     * terminal, set `keepVisible` to true.
     * @param {string} command
     * @param {boolean} keepVisible
     */
    prepareWith(command, keepVisible) {
        return new Promise((resolve, _) => {
@@ -256,13 +263,14 @@ class Test {

    /**
     * Return the next unsolved exercise, given the current state that's given as parameter
     * @param {State} state The current state
     */
    getNextUnsolvedExercise(currentState) {
        if (currentState.solvedExercises.length === this.exercises.length) {
    getNextUnsolvedExercise(state) {
        if (state.solvedExercises.length === this.exercises.length) {
            return null
        } else {
            let nextUnsolvedExerciseIndex = currentState.exerciseIndex || 0
            while (currentState.solvedExercises.includes(nextUnsolvedExerciseIndex)) {
            let nextUnsolvedExerciseIndex = state.exerciseIndex || 0
            while (state.solvedExercises.includes(nextUnsolvedExerciseIndex)) {
                nextUnsolvedExerciseIndex = (nextUnsolvedExerciseIndex + 1) % this.exercises.length
            }
    
@@ -272,26 +280,29 @@ class Test {

    /**
     * Return if the welcome message was already read in the current state
     * @param {State} state The current state
     */
    wasWelcomeRead(currentState) {
    wasWelcomeRead(state) {
        // TODO Properly implement this for each test separately
        return !currentState.firstStart
        return !state.firstStart
    }

    /**
     * Marks the welcome message as read, modifying the given current state
     * @param {State} state The current state
     */
    markWelcomeAsRead(currentState) {
    markWelcomeAsRead(state) {
        // TODO Properly implement this for each test separately
        currentState.firstStart = false
        state.firstStart = false
    }

    /**
     * Get the hand-in token to hand in this test
     * @param {State} state The current state
     */
    getHandInToken(currentState) {
    getHandInToken(state) {
        // TODO Properly implement this for each test separately
        return getHandInToken(currentState)
        return getHandInToken(state)
    }
}

+5 −2
Original line number Diff line number Diff line
/** Library providing a false sense of security **/

import { State } from "./state.mjs";

/**
 * Return a hand-in token, which is a gibberish string using which the GT can 
 * verify the student successfully completed the pool test
 * @returns The hand-in token
 * @param {State} state The current state
 */
export function getHandInToken(currentState) {
export function getHandInToken(state) {
    /*
     * Hello!
     *
@@ -40,5 +43,5 @@ export function getHandInToken(currentState) {
     * fixes this issue), feel free to have a look at
     * https://www.cl.uni-heidelberg.de/gruppetechnik/yalikejazz-docker.php
     */
    return btoa(currentState.toString())
    return btoa(state.toString())
}