Skip to content

Commit

Permalink
test(intg): evaluate continuously
Browse files Browse the repository at this point in the history
  • Loading branch information
lemredd committed Dec 24, 2022
1 parent fc5f9c4 commit dd5a024
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/components/CalculatorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,36 @@ function appendToEvaluationScreen(valueToAppend: PossibleButtonValues) {
const isEvaluating = valueToAppend === "="
mustResetOnNextEntry.value = true
if (!isEvaluating && !leftEntry.value) leftEntry.value = entryValue.value
if (!isEvaluating && !leftEntry.value) {
leftEntry.value = entryValue.value
operation.value = String(valueToAppend)
}
if (isEvaluating && !rightEntry.value) rightEntry.value = entryValue.value
if (!isEvaluationValueEmpty.value) evaluationValue.value += ` ${entryValue.value} ${valueToAppend}`
else evaluationValue.value = `${entryValue.value} ${valueToAppend}`
}
// Evaluated data and mutators
const previousEvaluatedValue = ref("0")
const isEntryValueEvaluated = computed(() => previousEvaluatedValue.value === entryValue.value)
function evaluateExpression(evaluationMethod: PossibleButtonValues) {
switch (evaluationMethod) {
case "=": {
function evaluateBasicOperation() {
if (!isEntryValueEvaluated.value) {
previousEvaluatedValue.value = String(evaluate(`${evaluationValue.value} ${entryValue.value}`))
appendToEvaluationScreen(evaluationMethod)
entryValue.value = previousEvaluatedValue.value
} else {
leftEntry.value = previousEvaluatedValue.value
evaluationValue.value = `${leftEntry.value} ${operation.value} ${rightEntry.value}`
previousEvaluatedValue.value = String(evaluate(evaluationValue.value))
evaluationValue.value += " ="
}
entryValue.value = previousEvaluatedValue.value
}
switch (evaluationMethod) {
case "=": {
evaluateBasicOperation()
break
}
case "%": {
Expand Down

0 comments on commit dd5a024

Please sign in to comment.