forked from GolangUnited/golang-united-school-homework-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_sum.go
27 lines (23 loc) · 1.13 KB
/
string_sum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package string_sum
import (
"errors"
)
//use these errors as appropriate, wrapping them with fmt.Errorf function
var (
// Use when the input is empty, and input is considered empty if the string contains only whitespace
errorEmptyInput = errors.New("input is empty")
// Use when the expression has number of operands not equal to two
errorNotTwoOperands = errors.New("expecting two operands, but received more or less")
)
// Implement a function that computes the sum of two int numbers written as a string
// For example, having an input string "3+5", it should return output string "8" and nil error
// Consider cases, when operands are negative ("-3+5" or "-3-5") and when input string contains whitespace (" 3 + 5 ")
//
//For the cases, when the input expression is not valid(contains characters, that are not numbers, +, - or whitespace)
// the function should return an empty string and an appropriate error from strconv package wrapped into your own error
// with fmt.Errorf function
//
// Use the errors defined above as described, again wrapping into fmt.Errorf
func StringSum(input string) (output string, err error) {
return "", nil
}