-
Notifications
You must be signed in to change notification settings - Fork 261
Add eval coverage for dotnet-test/grade-tests #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/dotnet-test/grade-tests/fixtures/go-table-driven/calculator.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package calc | ||
|
|
||
| import "errors" | ||
|
|
||
| // Add returns the sum of a and b. | ||
| func Add(a, b int) int { | ||
| return a + b | ||
| } | ||
|
|
||
| // Divide returns a/b, or an error when b is zero. | ||
| func Divide(a, b int) (int, error) { | ||
| if b == 0 { | ||
| return 0, errors.New("division by zero") | ||
| } | ||
| return a / b, nil | ||
| } | ||
|
|
||
| // Parse converts s to an int. It is intentionally simple for the fixture. | ||
| func Parse(s string) (int, error) { | ||
| n := 0 | ||
| for _, r := range s { | ||
| if r < '0' || r > '9' { | ||
| return 0, errors.New("not a number") | ||
| } | ||
| n = n*10 + int(r-'0') | ||
| } | ||
| return n, nil | ||
| } | ||
|
|
||
| // Reset clears the accumulator (no return value). | ||
| func Reset() {} |
62 changes: 62 additions & 0 deletions
62
tests/dotnet-test/grade-tests/fixtures/go-table-driven/calculator_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package calc | ||
|
|
||
| import "testing" | ||
|
|
||
| // ============================================================ | ||
| // STRONG TEST: idiomatic table-driven test with subtests. | ||
| // The `for` loop and the `if got != tt.want` comparison are | ||
| // the canonical Go assertion pattern, NOT branching/conditional | ||
| // logic in the test under grade. | ||
| // Expected grade: A (90–100) | ||
| // ============================================================ | ||
| func TestAdd_TableDriven(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| a, b int | ||
| want int | ||
| }{ | ||
| {"positives", 2, 3, 5}, | ||
| {"with zero", 0, 7, 7}, | ||
| {"negatives", -4, -6, -10}, | ||
| {"mixed sign", -2, 5, 3}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := Add(tt.a, tt.b) | ||
| if got != tt.want { | ||
| t.Errorf("Add(%d, %d) = %d, want %d", tt.a, tt.b, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // STRONG TEST: error path verified by checking the returned error. | ||
| // Expected grade: A (90–100) | ||
| // ============================================================ | ||
| func TestDivide_ByZero(t *testing.T) { | ||
| _, err := Divide(10, 0) | ||
| if err == nil { | ||
| t.Fatal("expected an error dividing by zero, got nil") | ||
| } | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // WEAK TEST: only checks that no error came back — does not | ||
| // verify the parsed value. Trivial assertion. | ||
| // Expected grade: C (70–79) | ||
| // ============================================================ | ||
| func TestParse_NoError(t *testing.T) { | ||
| _, err := Parse("123") | ||
| if err != nil { | ||
| t.Errorf("unexpected error: %v", err) | ||
| } | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // BAD TEST: calls the function but never asserts anything. | ||
| // Expected grade: F (0–59) | ||
| // ============================================================ | ||
| func TestReset_NoAssertions(t *testing.T) { | ||
| Reset() | ||
| } |
3 changes: 3 additions & 0 deletions
3
tests/dotnet-test/grade-tests/fixtures/go-table-driven/go.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module calc | ||
|
|
||
| go 1.22 |
61 changes: 61 additions & 0 deletions
61
...et-test/grade-tests/fixtures/production-unavailable/Payments.Tests/PaymentGatewayTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using Payments.Core; // Production assembly is NOT present in this fixture. | ||
|
|
||
| namespace Payments.Tests; | ||
|
|
||
| [TestClass] | ||
| public class PaymentGatewayTests | ||
| { | ||
| // ============================================================ | ||
| // STRONG TEST: AAA structure, equality assertion on the result. | ||
| // Expected grade: A (90–100) | ||
| // ============================================================ | ||
| [TestMethod] | ||
| public void Charge_ValidCard_ReturnsApprovedResult() | ||
| { | ||
| var gateway = new PaymentGateway(); | ||
|
|
||
| var result = gateway.Charge("4111111111111111", 49.99m); | ||
|
|
||
| Assert.AreEqual(PaymentStatus.Approved, result.Status); | ||
| Assert.AreEqual(49.99m, result.AmountCharged); | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // STRONG TEST: exception path is complete on its own. | ||
| // Expected grade: A (90–100) | ||
| // ============================================================ | ||
| [TestMethod] | ||
| public void Charge_NegativeAmount_ThrowsArgumentOutOfRange() | ||
| { | ||
| var gateway = new PaymentGateway(); | ||
|
|
||
| Assert.ThrowsException<ArgumentOutOfRangeException>( | ||
| () => gateway.Charge("4111111111111111", -1m)); | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // WEAK TEST: only a not-null check on the returned receipt. | ||
| // Expected grade: C (70–79) | ||
| // ============================================================ | ||
| [TestMethod] | ||
| public void Refund_ExistingCharge_ReturnsReceipt() | ||
| { | ||
| var gateway = new PaymentGateway(); | ||
|
|
||
| var receipt = gateway.Refund("txn-123"); | ||
|
|
||
| Assert.IsNotNull(receipt); | ||
| } | ||
|
|
||
| // ============================================================ | ||
| // BAD TEST: no assertions at all. | ||
| // Expected grade: F (0–59) | ||
| // ============================================================ | ||
| [TestMethod] | ||
| public void Settle_PendingBatch_Runs() | ||
| { | ||
| var gateway = new PaymentGateway(); | ||
| gateway.SettleBatch(); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...net-test/grade-tests/fixtures/production-unavailable/Payments.Tests/Payments.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
| <PackageReference Include="MSTest.TestFramework" Version="3.6.0" /> | ||
| <PackageReference Include="MSTest.TestAdapter" Version="3.6.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- NOTE: the production project under test (Payments.Core) is intentionally | ||
| NOT referenced or present in this fixture. The code under test is | ||
| unavailable, so behavioral concerns must be marked Unverified. --> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.