summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-11-25 22:40:51 +0200
committerPaul Buetow <paul@buetow.org>2025-11-25 22:40:51 +0200
commit488aeb5506e6b4ce34e88ea29cf01971531eb0b6 (patch)
treeb5d2df0c0de17f36f4a196abb4645e9cddf0b90d
parent19df58652909a9c58f99b268fa8c9de23a7e3eca (diff)
Add calculation steps to output, bump version to v0.1.0v0.1.0
Amp-Thread-ID: https://ampcode.com/threads/T-3883950c-6af3-4944-8596-7a40341c9c58 Co-authored-by: Amp <amp@ampcode.com>
-rw-r--r--internal/calculator/calculator.go18
-rw-r--r--internal/calculator/calculator_test.go21
-rw-r--r--internal/version.go2
3 files changed, 31 insertions, 10 deletions
diff --git a/internal/calculator/calculator.go b/internal/calculator/calculator.go
index ee1ff6f..fdca99b 100644
--- a/internal/calculator/calculator.go
+++ b/internal/calculator/calculator.go
@@ -39,7 +39,11 @@ func parseXPercentOfY(input string) (string, bool) {
base, _ := strconv.ParseFloat(matches[2], 64)
result := (percent / 100.0) * base
- return fmt.Sprintf("%.2f%% of %.2f = %.2f", percent, base, result), true
+
+ output := fmt.Sprintf("%.2f%% of %.2f = %.2f\n", percent, base, result)
+ output += fmt.Sprintf(" Steps: (%.2f / 100) * %.2f = %.2f * %.2f = %.2f", percent, base, percent/100.0, base, result)
+
+ return output, true
}
func parseXIsWhatPercentOfY(input string) (string, bool) {
@@ -58,7 +62,11 @@ func parseXIsWhatPercentOfY(input string) (string, bool) {
}
percent := (part / whole) * 100.0
- return fmt.Sprintf("%.2f is %.2f%% of %.2f", part, percent, whole), true
+
+ output := fmt.Sprintf("%.2f is %.2f%% of %.2f\n", part, percent, whole)
+ output += fmt.Sprintf(" Steps: (%.2f / %.2f) * 100 = %.2f * 100 = %.2f%%", part, whole, part/whole, percent)
+
+ return output, true
}
func parseXIsYPercentOfWhat(input string) (string, bool) {
@@ -77,5 +85,9 @@ func parseXIsYPercentOfWhat(input string) (string, bool) {
}
whole := (part / percent) * 100.0
- return fmt.Sprintf("%.2f is %.2f%% of %.2f", part, percent, whole), true
+
+ output := fmt.Sprintf("%.2f is %.2f%% of %.2f\n", part, percent, whole)
+ output += fmt.Sprintf(" Steps: (%.2f / %.2f) * 100 = %.2f * 100 = %.2f", part, percent, part/percent, whole)
+
+ return output, true
}
diff --git a/internal/calculator/calculator_test.go b/internal/calculator/calculator_test.go
index defbd13..2724d71 100644
--- a/internal/calculator/calculator_test.go
+++ b/internal/calculator/calculator_test.go
@@ -49,8 +49,11 @@ func TestParseXPercentOfY(t *testing.T) {
if err != nil {
t.Fatalf("Parse(%q) returned error: %v", tt.input, err)
}
- if result != tt.expected {
- t.Errorf("Parse(%q) = %q, expected %q", tt.input, result, tt.expected)
+ if !strings.HasPrefix(result, tt.expected) {
+ t.Errorf("Parse(%q) = %q, expected to start with %q", tt.input, result, tt.expected)
+ }
+ if !strings.Contains(result, "Steps:") {
+ t.Errorf("Parse(%q) = %q, expected to contain calculation steps", tt.input, result)
}
})
}
@@ -95,8 +98,11 @@ func TestParseXIsWhatPercentOfY(t *testing.T) {
if err != nil {
t.Fatalf("Parse(%q) returned error: %v", tt.input, err)
}
- if result != tt.expected {
- t.Errorf("Parse(%q) = %q, expected %q", tt.input, result, tt.expected)
+ if !strings.HasPrefix(result, tt.expected) {
+ t.Errorf("Parse(%q) = %q, expected to start with %q", tt.input, result, tt.expected)
+ }
+ if !strings.Contains(result, "Steps:") {
+ t.Errorf("Parse(%q) = %q, expected to contain calculation steps", tt.input, result)
}
})
}
@@ -141,8 +147,11 @@ func TestParseXIsYPercentOfWhat(t *testing.T) {
if err != nil {
t.Fatalf("Parse(%q) returned error: %v", tt.input, err)
}
- if result != tt.expected {
- t.Errorf("Parse(%q) = %q, expected %q", tt.input, result, tt.expected)
+ if !strings.HasPrefix(result, tt.expected) {
+ t.Errorf("Parse(%q) = %q, expected to start with %q", tt.input, result, tt.expected)
+ }
+ if !strings.Contains(result, "Steps:") {
+ t.Errorf("Parse(%q) = %q, expected to contain calculation steps", tt.input, result)
}
})
}
diff --git a/internal/version.go b/internal/version.go
index 3eeaed5..8826dc9 100644
--- a/internal/version.go
+++ b/internal/version.go
@@ -1,3 +1,3 @@
package internal
-const Version = "v0.0.1"
+const Version = "v0.1.0"