Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 7fa23af

Browse files
committed
Get DAG grader tests up and running
1 parent 81dd95f commit 7fa23af

File tree

2 files changed

+90
-27
lines changed

2 files changed

+90
-27
lines changed

runestone/parsons/test/_sources/index.rst

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -118,34 +118,32 @@ Section 2: Labeling
118118
Proof Blocks
119119
============
120120

121-
.. parsonsprob:: test_parsons_4
122-
:language: math
123-
:grader: dag
121+
.. parsonsprob:: test_proof_blocks_1
122+
:language: math
123+
:grader: dag
124124

125-
.. raw:: html
125+
.. raw:: html
126126

127-
<embed> Drag and drop <strong style="color:red;">all</strong> of the blocks below to create a proof by induction of the following statement.
128-
Claim: for all natural numbers \(n\),
129-
$$
130-
\sum_{j=0}^n 2(-7)^j = \frac{1-(-7)^{n+1}}{4}
131-
$$
127+
<embed>
128+
<p>Drag and drop <font color="red"><strong>ALL</strong></font> of the blocks below to create a proof of the following statement.</p>
129+
<center><font color="red">If graphs $G$ and $H$ are isomorphic and $G$ is 2-colorable, then $H$ is 2-colorable.</font></center>
132130
</embed>
133131

134-
-----
135-
Proof by induction on \(n\). #tag:0;depends:;
136-
=====
137-
Inductive Predicate: \(P(n): \sum_{j=0}^n 2(-7)^j = \frac{1-(-7)^{n+1}}{4}\) #tag:1;depends:0;
138-
=====
139-
Base case: At \(n=0\), \(\sum_{j=0}^n 2(-7)^j = 2\) and \(\frac{1-(-7)^{n+1}}{4} = \frac{1-(-7)}{4} = 2\), so the base case, \(P(0)\), holds #tag:2;depends:0,1;
140-
=====
141-
Inductive Hypothesis: Suppose that \(P(n):\) \(\sum_{j=0}^n 2(-7)^j = \frac{1-(-7)^{n+1}}{4}\) holds for \(n=0,1,...,k\). #tag:3;depends:1;
142-
=====
143-
Inductive Step: We need to show that \(P(k+1):\) \(\sum_{j=0}^{k+1} 2(-7)^j = \frac{1-(-7)^{k+2}}{4}\) holds #tag:4;depends:3;
144-
=====
145-
The left hand side is \(\sum_{j=0}^{k+1} 2(-7)^j = \sum_{j=0}^k 2(-7)^j + 2(-7)^{k+1}\) #tag:5;depends:4;
146-
=====
147-
By the inductive hypothesis we have \(\sum_{j=0}^k 2(-7)^j = \frac{1-(-7)^{k+1}}{4}\). So then substituting we get \(= \frac{1-(-7)^{k+1}}{4} + 2(-7)^{k+1}\) \(= \frac{1-(-7)^{k+1} + 8(-7)^{k+1}}{4}\) \(= \frac{1+7(-7)^{k+1}}{4}\) which simplifies to \(= \frac{1-(-7)^{k+2}}{4}\) #tag:6;depends:5;
148-
=====
149-
So \(\sum_{j=0}^{k+1} 2(-7)^j = \frac{1-(-7)^{k+2}}{4}\), which was what we needed to show. #tag:7;depends:6;
150-
151-
132+
-----
133+
Assume $G$ and $H$ are isomorphic graphs and $G$ is 2-colorable. #tag:0; depends:;
134+
=====
135+
Let $c:V(G) \to \{red, blue\}$ be a 2-coloring of $G$. #tag: 1; depends:0;
136+
=====
137+
Let $f$ be an isomorphism $V(H) \to V(G)$ #tag: 2; depends: 0;
138+
=====
139+
Define $c':V(H) \to \{red, blue\}$ as $c'(v)=c(f(v))$ #tag:3;depends:1,2;
140+
=====
141+
Let $\langle u - v \rangle$ be an edge in $H$. (If instead there are no edges in $H$, then $H$ is trivially 2-colorable and we are done.) #tag:4;depends:0;
142+
=====
143+
$\langle f(u) - f(v) \rangle$ is an edge in $G$ #tag:5;depends:4,2;
144+
=====
145+
$c(f(u)) \ne c(f(v))$ #tag:6;depends:5,1;
146+
=====
147+
$c'(u) \ne c'(v)$ #tag:7;depends:6,3;
148+
=====
149+
$c'$ is a 2-coloring of $H$, so $H$ is 2-colorable. (end of proof) #tag:8;depends:7;

runestone/parsons/test/test_parsons.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,71 @@ def test_indentation(selenium_utils_get):
292292
assert b3.get_attribute("class") == "block indentRight"
293293

294294

295+
def test_dag_grader(selenium_utils_get):
296+
selenium_utils_get.wait_until_ready("test_proof_blocks_1")
297+
298+
source = selenium_utils_get.driver.find_element_by_id("parsons-6-source")
299+
answer = selenium_utils_get.driver.find_element_by_id("parsons-6-answer")
300+
checkme = selenium_utils_get.driver.find_element_by_id("parsons-6-check")
301+
reset = selenium_utils_get.driver.find_element_by_id("parsons-6-reset")
302+
303+
def drag_block(block, before_block):
304+
ActionChains(selenium_utils_get.driver).drag_and_drop(
305+
source.find_element_by_id("parsons-6-block-" + str(block)),
306+
answer.find_element_by_id("parsons-6-block-" + str(before_block))
307+
).perform()
308+
309+
310+
reset.click()
311+
312+
ActionChains(selenium_utils_get.driver).drag_and_drop(
313+
source.find_element_by_id("parsons-6-block-8"), answer
314+
).perform()
315+
316+
for i in range(8, 0, -1):
317+
drag_block(i - 1, i)
318+
wait_for_animation(selenium_utils_get, "#parsons-6-block-0")
319+
checkme.click()
320+
message = selenium_utils_get.driver.find_element_by_id("parsons-6-message")
321+
assert message.get_attribute("class") == "alert alert-info"
322+
323+
reset.click()
324+
325+
ActionChains(selenium_utils_get.driver).drag_and_drop(
326+
source.find_element_by_id("parsons-6-block-3"), answer
327+
).perform()
328+
drag_block(7, 3)
329+
drag_block(6, 7)
330+
drag_block(8, 6)
331+
drag_block(4, 8)
332+
drag_block(1, 4)
333+
drag_block(2, 1)
334+
drag_block(0, 2)
335+
drag_block(5, 1)
336+
wait_for_animation(selenium_utils_get, "#parsons-6-block-5")
337+
checkme.click()
338+
message = selenium_utils_get.driver.find_element_by_id("parsons-6-message")
339+
assert message.get_attribute("class") == "alert alert-danger"
340+
341+
reset.click()
342+
343+
ActionChains(selenium_utils_get.driver).drag_and_drop(
344+
source.find_element_by_id("parsons-6-block-8"), answer
345+
).perform()
346+
drag_block(7, 8)
347+
drag_block(6, 7)
348+
drag_block(3, 6)
349+
drag_block(4, 3)
350+
drag_block(1, 4)
351+
drag_block(2, 1)
352+
drag_block(0, 2)
353+
drag_block(5, 3)
354+
wait_for_animation(selenium_utils_get, "#parsons-6-block-5")
355+
checkme.click()
356+
message = selenium_utils_get.driver.find_element_by_id("parsons-6-message")
357+
assert message.get_attribute("class") == "alert alert-info"
358+
359+
295360
def wait_for_animation(selenium_utils, selector):
296361
while is_element_animated(selenium_utils, selector):
297362
time.sleep(0.5)

0 commit comments

Comments
 (0)