Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Self-healing-LLM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ammar Ahmed
Self-healing-LLM
Commits
b2b47467
Commit
b2b47467
authored
7 months ago
by
Aleksander Einarsen
Browse files
Options
Downloads
Patches
Plain Diff
#86
Updated tests and test file contents
parent
8af937f4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/compiler_v2/go_compiler_v2/go_compiler_test.go
+3
-3
3 additions, 3 deletions
modules/compiler_v2/go_compiler_v2/go_compiler_test.go
modules/compiler_v2/go_compiler_v2/should_compile_and_run_tests
+54
-30
54 additions, 30 deletions
...s/compiler_v2/go_compiler_v2/should_compile_and_run_tests
with
57 additions
and
33 deletions
modules/compiler_v2/go_compiler_v2/go_compiler_test.go
+
3
−
3
View file @
b2b47467
...
@@ -31,9 +31,9 @@ func TestCompileStringToGo(t *testing.T) {
...
@@ -31,9 +31,9 @@ func TestCompileStringToGo(t *testing.T) {
filename
:
"should_compile_and_run_tests"
,
filename
:
"should_compile_and_run_tests"
,
shouldCompile
:
true
,
shouldCompile
:
true
,
},
},
{
{
// TODO might change name from should compile to should succeed
filename
:
"should_compile_with_faulty_test"
,
filename
:
"should_compile_with_faulty_test"
,
// Code is syntactically correct, but the test is faulty
shouldCompile
:
true
,
shouldCompile
:
false
,
// Here the test is faulty, so it will get a compiler error
},
},
}
}
...
...
This diff is collapsed.
Click to expand it.
modules/compiler_v2/go_compiler_v2/should_compile_and_run_tests
+
54
−
30
View file @
b2b47467
package main
package main
import (
import (
"errors"
"errors"
"fmt"
"fmt"
"testing"
"testing"
)
)
// Divide divides two numbers and returns the result.
// Divide divides two numbers and returns the result.
// Returns an error if division by zero is attempted.
// Returns an error if division by zero is attempted.
func Divide(a, b float64) (float64, error) {
func Divide(a, b float64) (float64, error) {
if b == 0 {
if b == 0 {
return 0, errors.New("cannot divide by zero")
return 0, errors.New("cannot divide by zero")
}
}
return a / b, nil
return a / b, nil
}
}
// Test cases for Divide function
// Test cases for Divide function
func TestDivide(t *testing.T) {
func TestDivide(t *testing.T) {
// Test case 1: Normal division
tests := []struct {
result, err := Divide(10, 2)
name string
if err != nil || result != 5 {
a float64
t.Errorf("Expected 5, got %v, error: %v", result, err)
b float64
}
expected float64
wantErr bool
}{
{
name: "Normal division",
a: 10,
b: 2,
expected: 5,
wantErr: false,
},
{
name: "Division by zero",
a: 10,
b: 0,
expected: 0, // expected is not used when wantErr is true
wantErr: true,
},
{
name: "Division with negative numbers",
a: -10,
b: 2,
expected: -5,
wantErr: false,
},
}
// Test case 2: Division by zero
for _, tt := range tests {
_, err = Divide(10, 0)
t.Run(tt.name, func(t *testing.T) {
if
err
=
=
nil {
result,
err
:
=
Divide(tt.a, tt.b)
t.Error("Expected error for division by zero, got nil")
if (err != nil) != tt.wantErr {
}
t.Errorf("Expected error: %v, got: %v", tt.wantErr, err)
}
// Test case 3: Division with negative numbers
if !tt.wantErr && result != tt.expected {
result, err = Divide(-10, 2
)
t.Errorf("Expected result: %v, got: %v", tt.expected, result
)
if err != nil || result != -5 {
}
t.Errorf("Expected -5, got %v, error: %v", result, err
)
}
)
}
}
}
}
// main function for demonstration purposes
// main function for demonstration purposes
func main() {
func main() {
a, b := 10.0, 2.0
a, b := 10.0, 2.0
result, err := Divide(a, b)
result, err := Divide(a, b)
if err != nil {
if err != nil {
fmt.Println("Error:", err)
fmt.Println("Error:", err)
} else {
} else {
fmt.Printf("Result of %.2f / %.2f = %.2f\n", a, b, result)
fmt.Printf("Result of %.2f / %.2f = %.2f\n", a, b, result)
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment