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

Two problem generators similar in structure: "Find Coefficient of Term" and "Evaluate Probability of Choice" Generators #138

Open
wants to merge 89 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
d10eb98
readme updates
NoahTheCorgi Oct 2, 2021
a28b9d1
readme updates in dynamic: wording changes
NoahTheCorgi Oct 2, 2021
43965f6
Update readme.md
NoahTheCorgi Oct 2, 2021
52bba5b
Update readme.md
NoahTheCorgi Oct 2, 2021
dded8e0
Update readme.md
NoahTheCorgi Oct 2, 2021
91306d6
Update readme.md
NoahTheCorgi Oct 2, 2021
bed5ed1
Update readme.md
NoahTheCorgi Oct 2, 2021
9f76a53
Update readme.md
NoahTheCorgi Oct 2, 2021
7428106
Update readme.md
NoahTheCorgi Oct 2, 2021
92dc4b9
Update readme.md
NoahTheCorgi Oct 2, 2021
97bb813
Update readme.md
NoahTheCorgi Oct 2, 2021
567ec33
Update readme.md
NoahTheCorgi Oct 2, 2021
c3bcf10
basic books in shelves code
NoahTheCorgi Oct 3, 2021
2f978d7
test_main.py updated so that it won't error due to randomized generation
NoahTheCorgi Oct 3, 2021
b555be5
Update main.py
NoahTheCorgi Oct 3, 2021
2b4d6da
Updated generate_question() in main.py so that three different types …
NoahTheCorgi Oct 3, 2021
f859854
question detail debugged
NoahTheCorgi Oct 3, 2021
6e364c3
Update main.py
NoahTheCorgi Oct 3, 2021
45da150
Update main.py
NoahTheCorgi Oct 3, 2021
efb8cda
Updated test_main so that it actually tests the properly asserts the …
NoahTheCorgi Oct 3, 2021
0eb279f
readme wrong data type mentioned fixed
NoahTheCorgi Oct 3, 2021
455b16d
readme updates
NoahTheCorgi Oct 2, 2021
6cf9762
readme updates in dynamic: wording changes
NoahTheCorgi Oct 2, 2021
1b08e00
Update readme.md
NoahTheCorgi Oct 2, 2021
f5fcc58
Update readme.md
NoahTheCorgi Oct 2, 2021
1bc1e5a
Update readme.md
NoahTheCorgi Oct 2, 2021
0d20772
Update readme.md
NoahTheCorgi Oct 2, 2021
110b92c
Update readme.md
NoahTheCorgi Oct 2, 2021
1ab8d1b
Update readme.md
NoahTheCorgi Oct 2, 2021
baa5590
Update readme.md
NoahTheCorgi Oct 2, 2021
3939e7e
Update readme.md
NoahTheCorgi Oct 2, 2021
f4872a3
Update readme.md
NoahTheCorgi Oct 2, 2021
b37f35e
Update readme.md
NoahTheCorgi Oct 2, 2021
f8b2aa7
basic books in shelves code
NoahTheCorgi Oct 3, 2021
6e3a8ce
test_main.py updated so that it won't error due to randomized generation
NoahTheCorgi Oct 3, 2021
69194b4
Update main.py
NoahTheCorgi Oct 3, 2021
bc46541
Updated generate_question() in main.py so that three different types …
NoahTheCorgi Oct 3, 2021
f253ca0
question detail debugged
NoahTheCorgi Oct 3, 2021
709277a
Update main.py
NoahTheCorgi Oct 3, 2021
ef5d63b
Update main.py
NoahTheCorgi Oct 3, 2021
2475255
Updated test_main so that it actually tests the properly asserts the …
NoahTheCorgi Oct 3, 2021
abb8a68
readme wrong data type mentioned fixed
NoahTheCorgi Oct 3, 2021
0699881
Merge branch 'master' of https://github.com/NoahTheCorgi/discretemath.ca
NoahTheCorgi Oct 4, 2021
24ee777
Update .gitignore
NoahTheCorgi Oct 4, 2021
5a80837
comments clean up
NoahTheCorgi Oct 7, 2021
d659dac
Completed All Books in Shelves Type Questions
NoahTheCorgi Oct 7, 2021
02a714c
test commit
NoahTheCorgi Oct 7, 2021
9f6e117
Create main.py
NoahTheCorgi Oct 7, 2021
d288a7c
test_main fix attempt
NoahTheCorgi Oct 7, 2021
6fabd42
Update test_main.py
NoahTheCorgi Oct 7, 2021
cd045da
got rid of global attributes of the variables and updated variable name
NoahTheCorgi Oct 9, 2021
6193ac0
test_main reworked using new TestOutput.py
NoahTheCorgi Oct 9, 2021
ae578f5
Update TestOutput.py
NoahTheCorgi Oct 9, 2021
ca17f37
Cleaned up spacing and empty lines
NoahTheCorgi Oct 9, 2021
800fda6
various fixes for test_output and code reusability
NoahTheCorgi Oct 19, 2021
9e9ce11
test_output small update
NoahTheCorgi Oct 19, 2021
5a3102a
test
NoahTheCorgi Oct 19, 2021
bdd0d32
Update test_output.py
NoahTheCorgi Oct 19, 2021
110b344
Update test_output.py
NoahTheCorgi Oct 19, 2021
745b787
test
NoahTheCorgi Oct 19, 2021
bd532e2
test
NoahTheCorgi Oct 19, 2021
5cb49d6
adjusted test_out.py (there seems to be a bug in the "checks" testing…
NoahTheCorgi Oct 19, 2021
88660e4
helper functions implemented to simplify and clean up each generators…
NoahTheCorgi Oct 21, 2021
0e9c012
stack edit implemented for readme files
NoahTheCorgi Oct 21, 2021
211c9ba
final commit (fixed all bugs)
NoahTheCorgi Oct 23, 2021
c414674
quick test
NoahTheCorgi Oct 23, 2021
924469c
Update test_main.py
NoahTheCorgi Oct 23, 2021
24696e7
"fixture bug" fixed
NoahTheCorgi Oct 23, 2021
6677f93
Update Navbar.svelte
NoahTheCorgi Oct 23, 2021
7dc74b9
Update HeaderInformation.svelte
NoahTheCorgi Oct 23, 2021
d8fdde3
Update HeaderInformation.svelte
NoahTheCorgi Oct 23, 2021
54b72e5
add pytest cache
MathyouMB Oct 30, 2021
7191482
removed uneccesary variables
MathyouMB Oct 30, 2021
1e02960
remove unused functions
MathyouMB Oct 30, 2021
c233929
add init pys
MathyouMB Oct 30, 2021
fc943d8
minor syntax changes
NoahTheCorgi Oct 30, 2021
312761d
Update books_shelves_helperfunctions.py
NoahTheCorgi Oct 31, 2021
557fdbb
Update books_shelves_helperfunctions.py
NoahTheCorgi Oct 31, 2021
604b416
remove package-lock
NoahTheCorgi Nov 20, 2021
cd9e72d
Merge branch 'master' into master
NoahTheCorgi Nov 20, 2021
2e26645
Fixed import issue
NoahTheCorgi Nov 27, 2021
07f7bff
Coefficient of a Term Problems Generator
NoahTheCorgi Mar 14, 2022
664d182
probability of choice problem generator
NoahTheCorgi Mar 14, 2022
eaf2de4
router.py re-formatted
NoahTheCorgi Mar 14, 2022
cbbae05
Merge branch 'master' into master
NoahTheCorgi Mar 14, 2022
53732ac
fixed imports so that local testpy all pass + fixed a small bug in ma…
NoahTheCorgi Mar 14, 2022
4373194
Merge branch 'master' of https://github.com/NoahTheCorgi/discretemath.ca
NoahTheCorgi Mar 14, 2022
4e9e0e1
adjusted the problem scenario to be unique compared to other pre-exis…
NoahTheCorgi Mar 14, 2022
9da12ac
Merge branch 'CarletonComputerScienceSociety:master' into master
NoahTheCorgi Apr 26, 2024
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
Empty file.
138 changes: 138 additions & 0 deletions dynamic/generators/comp2804/coefficient_of_term/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
""" What is the coefficient of x^a * y^b for the expansion of (cx^s+dy^t)^n ? """
""" This generator creates a randomized problem of figure out the coefficient
of a specific form x^{a}y^{b} for a given (cx^s+dy^t)^n """

import random


def generate_question():

s = random.randint(1, 5)
t = random.randint(1, 5)

multiply_s = random.randint(5, 15)
multiply_t = random.randint(5, 15)

a = s * multiply_s
b = t * multiply_t

c = random.randint(2, 7)
d = random.randint(2, 7)

n = multiply_s + multiply_t

question_body = (
"What is the coefficient of the term $x^{"
+ str(a)
+ "}y^{"
+ str(b)
+ "}$, in the expansion of "
+ "$("
+ str(c)
+ " \\cdot x^{"
+ str(s)
+ "} + "
+ str(d)
+ " \\cdot y^{"
+ str(t)
+ "})"
+ "^{"
+ str(n)
+ "}$"
)

answer = (
"$\\binom{"
+ str(n)
+ "}{"
+ str(multiply_s)
+ "} \\cdot "
+ str(c)
+ "^{"
+ str(multiply_s)
+ "} \\cdot "
+ str(d)
+ "^{"
+ str(multiply_t)
+ "}$"
)
varied_answer_1 = (
"$\\binom{"
+ str(n)
+ "}{"
+ str(multiply_s)
+ "} \\cdot "
+ str(c)
+ "^{"
+ str(a)
+ "} \\cdot "
+ str(d)
+ "^{"
+ str(b)
+ "}$"
)
varied_answer_2 = (
"$\\binom{"
+ str(n)
+ "}{"
+ str(s)
+ "} \\cdot "
+ str(c)
+ "^{"
+ str(s)
+ "} \\cdot "
+ str(d)
+ "^{"
+ str(t)
+ "}$"
)
varied_answer_3 = (
"$\\binom{"
+ str(n)
+ "}{"
+ str(s)
+ "} \\cdot "
+ str(c)
+ "^{"
+ str(multiply_s)
+ "} \\cdot "
+ str(d)
+ "^{"
+ str(multiply_t)
+ "}$"
)

# we will not randomize the order of these choices because that is handled in ruby side.
# random.shuffle(answerchoices)
return {
"title": "coefficient_of_term",
"body": question_body,
"bodyFormat": "mathjax",
"pseudocode": "",
"multipleChoiceAnswers": [
{
"body": answer,
"bodyFormat": "mathjax",
"correct": "true",
},
{
"body": varied_answer_1,
"bodyFormat": "mathjax",
"correct": "false",
},
{
"body": varied_answer_2,
"bodyFormat": "mathjax",
"correct": "false",
},
{
"body": varied_answer_3,
"bodyFormat": "mathjax",
"correct": "false",
},
],
}


def call():
return generate_question()
11 changes: 11 additions & 0 deletions dynamic/generators/comp2804/coefficient_of_term/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .test_out import test_output

# import test_out
import sys

# import main as main
from .main import call


def test():
assert test_output(call())
110 changes: 110 additions & 0 deletions dynamic/generators/comp2804/coefficient_of_term/test_out.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
""" This file contains tools for test_main.py to use. """


def check_mathjax_compatible(output_string):
# for now, checks that the answers start and end with the "$" to be conventionally compatible with mathjax
# could change the conditions to accommodate more types of mathjax compatible examples ...
return output_string[0] == "$" and output_string[len(output_string) - 1] == "$"


# returns True if the output dictionary is a valid output for the "ruby side" interpretation
def test_output(cache):

bodyFormat_options = ["text", "mathjax"] # can add more options in the future

if type(cache) != type({}):
return False
else:

answer_type = {
"title": "",
"body": "",
"bodyFormat": "mathjax", # or "text"
"pseudocode": "",
"multipleChoiceAnswers": [
{
"body": "",
"bodyFormat": "mathjax",
"correct": "true",
},
{
"body": "",
"bodyFormat": "mathjax",
"correct": "false",
},
{
"body": "",
"bodyFormat": "mathjax",
"correct": "false",
},
{
"body": "",
"bodyFormat": "mathjax",
"correct": "false",
},
],
}

keys_list = list(
answer_type.keys()
) # the list of keys from the template answer_type dictionary
out_list = list(
cache.keys()
) # the list of keys from the output dictionary that we are testing

# checks if the output dictionary that is being tested has the correct type of keys as in the answer_type
for i in range(len(out_list)):
if not out_list[i] in keys_list:
return False

# if there is "title" key in the ouput dictionary, check that the item of "title" is string type
if "title" in out_list:
if not type(cache["title"]) == type(""):
return False

# check that the item of the key, "body", is string type
if not type(cache["body"]) == type(""):
return False

# checks "bodyFormat" key has the correct item types available as in the bodyFormat_options
if not (cache["bodyFormat"] in bodyFormat_options):
return False

# if there is "pseudocode" key in the output dictionary, check that the item of "pseudocode" is a string type
if "pseudocode" in out_list:
if not type(cache["pseudocode"]) == type(""):
return False

# tests the item of "multipleChoiceAnswers" key
mult_choice_answers = cache[keys_list[4]]
if len(mult_choice_answers) != 4:
return False
else:

for i in range(0, 4):

if type(mult_choice_answers[i]) != type({}):
return False
elif len(mult_choice_answers[i]) != 3:
return False

for j in range(len(list(mult_choice_answers[i].keys()))):
if not (
list(mult_choice_answers[i].keys())[j]
in ["body", "bodyFormat", "correct"]
):
return False

if not check_mathjax_compatible(mult_choice_answers[i]["body"]):
return False

if not (mult_choice_answers[i]["bodyFormat"] in bodyFormat_options):
return False

if not (
mult_choice_answers[i]["correct"] == "true"
or mult_choice_answers[i]["correct"] == "false"
):
return False

return True
Empty file.
Loading
Loading