-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
it('can create compare numbers worksheet', () => { | ||
cy.visitWorksheetCompareNumbers(); | ||
|
||
cy.findByLabelText(/count/i).clearType('8'); | ||
cy.findByLabelText(/magnitude/i).select('Hundreds'); | ||
cy.findByLabelText(/columns/i).clearType('2'); | ||
cy.withinPreview(() => { | ||
cy.findByRole('list', { name: 'Problems' }).within((subject) => { | ||
cy.wrap(subject).findAllByRole('listitem') | ||
.should('have.length', 8) | ||
.each(($li) => { | ||
cy.wrap($li).contains(/\d+\s+_+\s+\d+/); | ||
}); | ||
}); | ||
|
||
cy.findByRole('list', { name: 'Answers' }).within((subject) => { | ||
cy.wrap(subject).findAllByRole('listitem') | ||
.should('have.length', 8) | ||
.each(($li) => { | ||
cy.wrap($li).contains(/\d+\s+(<|>|=)\s+\d+/); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Magnitude } from '../../lib/math/magnitude'; | ||
|
||
export type NumberComparison = '>' | '<' | '='; | ||
export const numberComparisons: NumberComparison[] = [ | ||
'>', | ||
'<', | ||
'=', | ||
]; | ||
|
||
export default interface CompareNumbersData { | ||
count: number; | ||
magnitude: Magnitude; | ||
columns: number; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import PrintableUI from '../../components/PrintableUI'; | ||
import usePageState from '../usePageState'; | ||
import CustomizeCompareNumbersForm from './CustomizeCompareNumbersForm'; | ||
import CompareNumbersData from './CompareNumbersData'; | ||
import PreviewCompareNumbers from './PreviewCompareNumbers'; | ||
|
||
const defaultData: CompareNumbersData = { | ||
count: 10, | ||
magnitude: 'tens', | ||
columns: 1, | ||
}; | ||
const key = 'compareNumbers'; | ||
|
||
function CompareNumbersPage(): JSX.Element { | ||
const { data, onChange } = usePageState<CompareNumbersData>({ | ||
key, defaultData, | ||
}); | ||
return ( | ||
<PrintableUI | ||
title="Compare Numbers" | ||
optionsKey={key} | ||
customizeForm={( | ||
<CustomizeCompareNumbersForm | ||
onChange={onChange} | ||
data={data} | ||
/> | ||
)} | ||
> | ||
<PreviewCompareNumbers data={data} /> | ||
</PrintableUI> | ||
); | ||
} | ||
|
||
export default CompareNumbersPage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { NumberComparison } from './CompareNumbersData'; | ||
|
||
class CompareNumbersProblem { | ||
left: number; | ||
|
||
right: number; | ||
|
||
constructor(left: number, right: number) { | ||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
symbol(): NumberComparison { | ||
if (this.left === this.right) { | ||
return '='; | ||
} | ||
return this.left > this.right ? '>' : '<'; | ||
} | ||
|
||
toString() { | ||
const symbol = this.symbol() as string; | ||
return `${this.left} ${symbol} ${this.right}`; | ||
} | ||
} | ||
|
||
export default CompareNumbersProblem; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { Divider } from '@material-ui/core'; | ||
import CustomizeForm from '../../components/forms/CustomizeForm'; | ||
import CompareNumbersData from './CompareNumbersData'; | ||
import NumberField from '../../components/forms/NumberField'; | ||
import { Magnitude, magnitudes } from '../../lib/math/magnitude'; | ||
import SelectField from '../../components/forms/SelectField'; | ||
import arrayToOptions from '../../components/forms/arrayToOptions'; | ||
|
||
interface CustomizeCompareNumbersFormProps { | ||
onChange: (data: CompareNumbersData) => void; | ||
data: CompareNumbersData; | ||
} | ||
|
||
function CustomizeCompareNumbersForm({ | ||
data, onChange, | ||
}: CustomizeCompareNumbersFormProps): JSX.Element { | ||
return ( | ||
<CustomizeForm name="Worksheet"> | ||
<NumberField | ||
name="count" | ||
label="Count" | ||
value={data.count} | ||
onChange={(count) => onChange({ ...data, count })} | ||
/> | ||
<SelectField<Magnitude> | ||
name="magnitude" | ||
value={data.magnitude} | ||
onChange={(magnitude) => onChange({ ...data, magnitude })} | ||
> | ||
{arrayToOptions(magnitudes, true)} | ||
</SelectField> | ||
|
||
<Divider variant="middle" /> | ||
<NumberField | ||
name="columns" | ||
value={data.columns} | ||
onChange={(columns) => onChange({ ...data, columns })} | ||
min={1} | ||
max={10} | ||
/> | ||
|
||
</CustomizeForm> | ||
); | ||
} | ||
|
||
export default CustomizeCompareNumbersForm; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import MultiPaperPage from '../../components/MultiPaperPage'; | ||
import PageTitle from '../../elements/PageTitle'; | ||
import ProblemList from '../../components/ProblemList'; | ||
import ProblemListItem from '../../components/ProblemListItem'; | ||
import WorksheetFooter from '../../components/printElements/WorksheetFooter'; | ||
import WorksheetHeader from '../../components/printElements/WorksheetHeader'; | ||
import CompareNumbersData from './CompareNumbersData'; | ||
import generateProblems from './generateProblems'; | ||
import CompareNumbersProblem from './CompareNumbersProblem'; | ||
import Blank from '../../components/Blank'; | ||
|
||
function itemBuilder( | ||
showAnswer: boolean, | ||
) { | ||
function fn(problem: CompareNumbersProblem, indexNumber: number) { | ||
return ( | ||
<ProblemListItem | ||
key={`problem-${indexNumber}`} | ||
className="compare-numbers-problem-item" | ||
label={`Compare Numbers ${showAnswer ? 'Answer' : 'Problem'}`} | ||
> | ||
{problem.left} | ||
{' '} | ||
<Blank showAnswer={showAnswer} answer={problem.symbol().toString()} /> | ||
{' '} | ||
{problem.right} | ||
</ProblemListItem> | ||
); | ||
} | ||
return fn; | ||
} | ||
|
||
interface PreviewCompareNumbersProps { | ||
data: CompareNumbersData; | ||
} | ||
|
||
function PreviewCompareNumbers({ data }: PreviewCompareNumbersProps): JSX.Element { | ||
const problems = generateProblems(data); | ||
const instructions = 'Write <, >, = if the number on the left is less than, greater than, or equal to the number on the right.'; | ||
|
||
return ( | ||
<> | ||
<MultiPaperPage | ||
header={( | ||
<WorksheetHeader> | ||
<p>{instructions}</p> | ||
</WorksheetHeader> | ||
)} | ||
wrapper={ProblemList} | ||
footer={(<WorksheetFooter itemCount={problems.length} />)} | ||
wrapperProps={{ | ||
className: 'problems', | ||
columns: data.columns, | ||
}} | ||
data={problems} | ||
itemSelector=".compare-numbers-problem-item" | ||
renderItems={itemBuilder(false)} | ||
/> | ||
<MultiPaperPage | ||
header={( | ||
<PageTitle>Answer Key</PageTitle> | ||
)} | ||
wrapper={ProblemList} | ||
wrapperProps={{ | ||
className: 'answers', | ||
label: 'Answers', | ||
columns: data.columns, | ||
}} | ||
data={problems} | ||
itemSelector=".compare-numbers-problem-item" | ||
renderItems={itemBuilder(true)} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default PreviewCompareNumbers; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { maxFromMagnitude } from '../../lib/math/magnitude'; | ||
import { randomGenerator, scaledRoulette, ScalingMap } from '../../lib/RandomNumberGenerator'; | ||
import CompareNumbersData, { NumberComparison } from './CompareNumbersData'; | ||
import CompareNumbersProblem from './CompareNumbersProblem'; | ||
|
||
const comparisonWeights: ScalingMap<NumberComparison> = new Map([ | ||
['<', 2], | ||
['>', 2], | ||
['=', 1], | ||
]); | ||
|
||
export default function generateProblems({ | ||
magnitude, count, | ||
}: CompareNumbersData): CompareNumbersProblem[] { | ||
const problems: CompareNumbersProblem[] = []; | ||
const max = maxFromMagnitude(magnitude); | ||
for (let i = 0; i < count; i++) { | ||
const comparison = scaledRoulette(comparisonWeights); | ||
let left: number; | ||
let right: number; | ||
if (comparison === '>') { | ||
left = randomGenerator.integer(max, 1); | ||
right = randomGenerator.integer(left - 1); | ||
} else if (comparison === '<') { | ||
left = randomGenerator.integer(max - 1); | ||
right = randomGenerator.integer(max, left + 1); | ||
} else { | ||
left = randomGenerator.integer(max); | ||
right = left; | ||
} | ||
problems.push(new CompareNumbersProblem(left, right)); | ||
} | ||
|
||
return problems; | ||
} |