Closed Yet-Zio closed 1 year ago
Possible fix:
private var booleanOpsList = arrayListOf("AND", "OR", "NAND", "NOR", "XOR", "Lsh", "Rsh") // NOT is unary, so not required
for(i in opsList){
if(tvExp.text.toString().contains(i) && tvExp.text.toString().trim().indexOf(i) == tvExp.text.toString().trim().lastIndex){
mViewModel.opPresent = true
break
}
if(i in booleanOpsList){
val inc = when (i) {
"OR" -> {
1
}
"NAND" -> {
3
}
else -> {
2
}
}
if(tvExp.text.toString().contains(i) && tvExp.text.toString().trim().indexOf(i) + inc == tvExp.text.toString().trim().lastIndex){
mViewModel.opPresent = true
break
}
}
}
Fixed as of #53
Problems
Based on #35, the issue repeats for boolean operators such as AND, OR, NOT, NAND, NOR, XOR, LSH and RSH but everything is fine for arithmetic operators.
Expected
Remember the operator in history string and do not calculate beforehand.
Causes
Current solution only compares start index of operator with the last index. https://github.com/Yet-Zio/yetCalc/blob/32d60114a3571f9c31f3ebcafa1ddd489ad3e244/app/src/main/java/yetzio/yetcalc/views/ProgramCalcActivity.kt#L711-L716
Possible Solution
Compare the last index for boolean operators.