Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringStartOrEnd Factory, LinkedQuestion Class and Component, Globe Animation #190

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6cb3e18
Add submit button to the Test.svelte
xxArchitect Jul 11, 2022
d825827
Add submitted property to the Examination class
xxArchitect Jul 11, 2022
ee8aaa7
Update examination state when test is submitted
xxArchitect Jul 11, 2022
52fa216
Pass submitted state to MultipleChoiceQuestion
xxArchitect Jul 11, 2022
8de890e
Pass submitted state and option correctness to MultipleChoiceOption
xxArchitect Jul 11, 2022
f32a129
Select proper background color based on conditions
xxArchitect Jul 11, 2022
f24aebc
Fix prettier formatting error
xxArchitect Jul 11, 2022
d17f0f6
Merge master branch of CarletonComputerScienceSociety into forked ma…
xxArchitect Jul 20, 2022
233bc5b
Merge branch 'CarletonComputerScienceSociety-master' into master
xxArchitect Jul 20, 2022
9c8239e
Create factory for StringStartOrEnd questions
xxArchitect Jul 20, 2022
c4eba58
Remove unncessary import
xxArchitect Jul 20, 2022
5087d11
Remove duplicate submit method
xxArchitect Jul 23, 2022
e42bd41
Merge pull request #2 from CarletonComputerScienceSociety/master
xxArchitect Jul 28, 2022
19fdece
Add LinkedQuestion component
xxArchitect Jul 28, 2022
162b38f
Fix formatting error
xxArchitect Jul 28, 2022
6a99bb1
Fix formatting error
xxArchitect Jul 28, 2022
a51c9af
Fix formatting error
xxArchitect Jul 28, 2022
18b5eb0
Merge pull request #3 from CarletonComputerScienceSociety/master
xxArchitect Aug 11, 2022
4378903
Create LinkedQuestion class
xxArchitect Aug 12, 2022
58404e2
Move and update LinkedQuestion component
xxArchitect Aug 12, 2022
7fd1c64
Add export file to LinkedQuestion component
xxArchitect Aug 12, 2022
41cb3de
Add GlobeAnimation component to the home page
xxArchitect Aug 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/apps/Examinations/lib/Examination.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Examination {
submit() {
this.submitted = true;
}

// Change state of examination to submitted
submit() {
this.submitted = true;
}
xxArchitect marked this conversation as resolved.
Show resolved Hide resolved
}

export { Examination };
138 changes: 138 additions & 0 deletions app/src/apps/Examinations/lib/factories/StringStartOrEnd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import Factory from "../Factory";
import { MultipleChoiceQuestion } from "../questions";

const MIN_STRING_SIZE = 3;
const MAX_STRING_SIZE = 16;
const MIN_ALPHABET_SIZE = 2;
const MAX_ALPHABET_SIZE = 6;
const FULL_ALPHABET = "abcdefghijklmnopqrstuvwxyz";

class StringStartOrEnd extends Factory {
create() {
const content = this.generateQuestionContent();
const body = this.generateQuestionBody(content);
const options = this.generateQuestionOptions(content);
const question = new MultipleChoiceQuestion(body, options);
return question;
}

getRandomAlphabetSize() {
return (
Math.floor(Math.random() * (MAX_ALPHABET_SIZE - MIN_ALPHABET_SIZE + 1)) +
MIN_ALPHABET_SIZE
);
}

getRandomStringLength() {
return (
Math.floor(Math.random() * (MAX_STRING_SIZE - MIN_STRING_SIZE + 1)) +
MIN_STRING_SIZE
);
}

// Generates random string based on the given alphabet and desired string length
getRandomString(alphabet, length) {
let result = "";
for (let i = 0; i < length; ++i)
result += alphabet.at(Math.floor(Math.random() * alphabet.length));
return result;
}

getSubstrings(strLength, alphabetSize) {
// generate available alphabet
let alphabet = FULL_ALPHABET.slice(0, alphabetSize);

// start substring length is at max 2 characters shorter than the total length of the string
let startSubstrLength = Math.floor(Math.random() * (strLength - 2)) + 1;
// end substring length will depend on the start substring length
let endSubstrLength =
Math.floor(Math.random() * (strLength - startSubstrLength - 1)) + 1;

let startSubstr = this.getRandomString(alphabet, startSubstrLength);
let endSubstr = this.getRandomString(alphabet, endSubstrLength);
return [startSubstr, endSubstr];
}

generateQuestionContent() {
const strLength = this.getRandomStringLength();
const alphabetSize = this.getRandomAlphabetSize();
const [startSubstr, endSubstr] = this.getSubstrings(
strLength,
alphabetSize
);
return { strLength, alphabetSize, startSubstr, endSubstr };
}

generateQuestionBody(questionContent) {
const { strLength, alphabetSize, startSubstr, endSubstr } = questionContent;
let alphabetString = FULL_ALPHABET.slice(0, alphabetSize)
.split("")
.join(", ");
return String.raw`Consider strings of length ${strLength} over the alphabet $\{${alphabetString}\}$. How many such strings are there that start with $${startSubstr}$ or end with $${endSubstr}$?`;
}

generateQuestionOptions(questionContent) {
const { strLength, alphabetSize, startSubstr, endSubstr } = questionContent;

let options = [];

options.push(this.generateOptionOne(strLength, alphabetSize, startSubstr));
options.push(
this.generateOptionTwo(strLength, alphabetSize, startSubstr, endSubstr)
);
options.push(
this.generateOptionThree(strLength, alphabetSize, startSubstr, endSubstr)
);
options.push(
this.generateOptionFour(strLength, alphabetSize, startSubstr, endSubstr)
);

options.sort(() => Math.random() - 0.5);

return options;
}

generateOptionOne(strLength, alphabetSize, startSubstr) {
// this generates the number of strings that start with the given substring
let result = alphabetSize ** (strLength - startSubstr.length);
return {
body: String.raw`$ {${result}} $`,
correct: false,
};
}

generateOptionTwo(strLength, alphabetSize, startSubstr, endSubstr) {
// this generates a falsy value that counts strings that start AND end with the given substrings
let result =
alphabetSize ** (strLength - startSubstr.length - endSubstr.length);
return {
body: String.raw`$ {${result}} $`,
correct: false,
};
}

generateOptionThree(strLength, alphabetSize, startSubstr, endSubstr) {
// this generates the correct answer
let result =
alphabetSize ** (strLength - startSubstr.length) +
alphabetSize ** (strLength - endSubstr.length) -
alphabetSize ** (strLength - startSubstr.length - endSubstr.length);
return {
body: String.raw`$ {${result}} $`,
correct: true,
};
}

generateOptionFour(strLength, alphabetSize, startSubstr, endSubstr) {
// this generates a falsy value that double counts strings that start AND end with the given substrings
let result =
alphabetSize ** (strLength - startSubstr.length) +
alphabetSize ** (strLength - endSubstr.length);
return {
body: String.raw`$ {${result}} $`,
correct: false,
};
}
}

export { StringStartOrEnd };