Created
July 29, 2020 10:57
-
-
Save alexdobry/ac7f8c0d0e08a0fbe9b023638e51311d to your computer and use it in GitHub Desktop.
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
import Array "mo:base/Array"; | |
type Question = { | |
#yesOrNo: { | |
question: Text; | |
solution: Bool; | |
}; | |
#freeform: { | |
question: Text | |
}; | |
}; | |
type Answer = { | |
#yesOrNo: Bool; | |
#freeform: Text; | |
}; | |
type Test = [(Question, ?Answer)]; | |
func renderQuestion(question: Question): Text { | |
switch (question) { | |
case (#yesOrNo(q)) | |
q.question; | |
case (#freeform(q)) | |
q.question; | |
}; | |
}; | |
actor { | |
var questions: [Question] = [ | |
#freeform({ question = "Welches Bier?" }), | |
#yesOrNo({ question = "Tabs or Spaces?"; solution = false }) | |
]; | |
var tests: [(Principal, Test)] = []; | |
// public func allQuestions() : async [Text] { | |
// Array.map(questions, renderQuestion) | |
// }; | |
public func allQuestions() : async [Question] { | |
questions; | |
}; | |
public func allTests() : async [(Principal, Test)] { | |
tests; | |
}; | |
public shared { caller } func createTest(indicies: [Nat]) { | |
let test: Test = Array.map<Nat, (Question, ?Answer)>(indicies, func i = (questions[i], null)); | |
// tests #= [(caller, test)]; | |
tests := Array.append(tests, [(caller, test)]); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment