Question: Overview In this assignment you will write a Go code to parse simple equations and test the function(s). The equations consist of only positive integers,
Overview
In this assignment you will write a Go code to parse simple equations and test the function(s). The equations consist of only positive integers, "+", "-", "*", and "/" operators with on both the left and right hand sides of the equation. White space is allowed. For example 7 + 2 /3 = 1*3. There is no program required for this assignment and therefore no "main" package.
Learning Objectives
Software testing including Go Examples, Unit Testing, Benchmark Testing, Fuzz Testing
Requirements
Complete the tasks as described in the source code in the project.
You code will be graded on completeness and form. So please write comprehensive tests that are well documented and follow the Go conventions.
Do not edit any file that has a comment toward the top stating so.
Do not use any library other than the Go standard library.
The source code must compile with the most recent version of the Go compiler.
The program must not panic under any circumstances.
package eqnparse
import "fmt"
// IMPLEMENT THIS // ParseEquation parses the given equation and return it otherwise it returns an error
func ParseEquation(equation string) (*Equation, error)
{ // STUDENTS: IMPLEMENT THIS FUNCTION
return nil, fmt.Errorf("not implemented")
}
package eqnparse
// STUDENTS: YOU MUST IMPLEMENT ALL OF THE BELOW TESTS IN THIS FILE // ExampleParseEquation // TestParseEquation // BenchmarkParseEquation // FuzzParseEquation
/* Example equations. Note equations do have to be mathematically valid 3-1=2 5*4+2=22 3-1=2 9*2=18 6*2/3=4 3 - 1 = 2 9 + 0 = 9 2 * 3 = 6 4 + 5 = 9 4 + 5 + 6 = 15 2 + 3 + 1 = 6 7+3-3=7* 1 */
package eqnparse
import "strconv"
// STUDENTS: MODIFY THE IMPLEMENTATIONS TO IMPROVE THE BENCHMARK
func (expr Expression) String() (s string) { for i := 0; i < len(expr.Numbers)+len(expr.Operators); i++ { if i%2 == 0 { // even s += strconv.Itoa(expr.Numbers[i/2]) } else { // odd s += string(expr.Operators[(i-1)/2]) } } return }
func (eqn Equation) String() string { return eqn.lhs.String() + "=" + eqn.rhs.String() }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
