Skip to content

Conversation

@thigiang16
Copy link

Worked with @JosephPotapenko. We implemented both Extra credits

Copy link

@katmilton katmilton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructions

Create a Console project called "Calculate.". ✔
Define a Program Class ✔
Define two init-only setter properties, WriteLine and ReadLine, that contain delegates for writing a line of text and reading a line of text respectively ✔
Write a test that sets these properties at construction time and then invokes the properties and verifies the expected behavior occurs. ✔
Set the default behavior for the WriteLine and ReadLine properties to invoke System.Console versions of the methods and add an empty default constructor. ✔
Define a Calculator class ✔
Define static Add, Subtract, Multiple, and Divide methods that have two parameters and return a third parameter. ✔
Define a read-only property, MathematicalOperations, of type System.Collections.Generics.IReadOnlyDictionary<TKey,TValue> that:
is initialized to a System.Collections.Generics.Dictionary<<TKey,TValue> instance that. ✔
Uses char for the key corresponding to the operators +, -, *, and /. ✔
Has values that correspond with the Add, Subtract, Multiple, and Divide methods. ✔
Implement a TryCalculate method following "TryParse" pattern ✔
Valid calculation expressions include such strings as "3 + 4", "42 - 2", etc. ✔
If there is no whitespace around the operator, you can assume the calculation is invalid and return false. Similarly if the operands are not integers. ✔
Use string.Split(), pattern matching, logical and operators to parse the string in their entirety ✔
Index into the MathematicalOperations method using the operator parsed during pattern matching to find the corresponding implementation and invoke it. ✔
Implement the Program class to instantiate the calculator and invoke it based on user input from the console. ✔
Be sure to use the WriteLine/ReadLine properties on Program for testing the input and output of your program. ✔

Extra Credit

Refactor the redirect portion of the Program class into 'ProgramBase`✔
Move ProgramBase into a ConsoleUtilities assembly to be used in other console-based projects ✔
Use generics the mathematical operations methods and consider using generic constraints (requires .NET 7.0)✔

Fundamentals

Place all shared project properties into a Directory.Build.props file.
Place all shared project items into a Directory.Build.targets file. (optional)
nullable reference types is enabled ✔
Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
Set LangVersion and the TargetFramework to the latest released versions available (preview versions optional) ✔
and enabled .NET analyzers for both projects ✔
For this assignment, always use Assert.AreEqual() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔

Good work!

Copy link

@ulises-aguilar ulises-aguilar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a Console project called "Calculate". ✔
Define a Program Class
Define two init-only setter properties, WriteLine and ReadLine, that contain delegates for writing a line of text and reading a line of text respectively ✔
Write a test that sets these properties at construction time and then invokes the properties and verifies the expected behavior occurs. ✔
Set the default behavior for the WriteLine and ReadLine properties to invoke System.Console versions of the methods and add an empty default constructor. ✔
Define a Calculator class ✔
Define static Add, Subtract, Multiply, and Divide methods that have two parameters and return a third parameter. ✔
Define a read-only property, MathematicalOperations, of type System.Collections.Generics.IReadOnlyDictionary<TKey,TValue> that:
is initialized to a System.Collections.Generics.Dictionary<<TKey,TValue> instance that. ✔
Uses char for the key corresponding to the operators +, -, *, and /. ✔
Has values that correspond with the Add, Subtract, Multiply, and Divide methods. ✔
Implement a TryCalculate method following "TryParse" pattern ✔
Valid calculation expressions include such strings as "3 + 4", "42 - 2", etc. ✔
If there is no whitespace around the operator, you can assume the calculation is invalid and return false. Similarly if the operands are not integers. ✔
Use string.Split(), pattern matching, logical and operators to parse the string in their entirety ✔
Index into the MathematicalOperations method using the operator parsed during pattern matching to find the corresponding implementation and invoke it. ✔
Implement the Program class to instantiate the calculator and invoke it based on user input from the console. ✔
Be sure to use the WriteLine/ReadLine properties on Program for testing the input and output of your program. ✔

@Hellothereyoko
Copy link

Create a Console project called "Calculate.". ✔
Define a Program Class ✔
Define two init-only setter properties, WriteLine and ReadLine, that contain delegates for writing a line of text and reading a line of text respectively ✔
Write a test that sets these properties at construction time and then invokes the properties and verifies the expected behavior occurs. ✔
Set the default behavior for the WriteLine and ReadLine properties to invoke System.Console versions of the methods and add an empty default constructor. ✔
Define a Calculator class ✔
Define static Add, Subtract, Multiple, and Divide methods that have two parameters and return a third parameter. ✔
Define a read-only property, MathematicalOperations, of type System.Collections.Generics.IReadOnlyDictionary<TKey,TValue> that:
is initialized to a System.Collections.Generics.Dictionary<<TKey,TValue> instance that. ✔
Uses char for the key corresponding to the operators +, -, *, and /. ✔
Has values that correspond with the Add, Subtract, Multiple, and Divide methods. ✔
Implement a TryCalculate method following "TryParse" pattern ✔
Valid calculation expressions include such strings as "3 + 4", "42 - 2", etc. ✔
If there is no whitespace around the operator, you can assume the calculation is invalid and return false. Similarly if the operands are not integers. ✔
Use string.Split(), pattern matching, logical and operators to parse the string in their entirety ✔
Index into the MathematicalOperations method using the operator parsed during pattern matching to find the corresponding implementation and invoke it. ✔
Implement the Program class to instantiate the calculator and invoke it based on user input from the console. ✔
Be sure to use the WriteLine/ReadLine properties on Program for testing the input and output of your program. ✔

Extra Credit

Refactor the redirect portion of the Program class into 'ProgramBase`✔
Move ProgramBase into a ConsoleUtilities assembly to be used in other console-based projects ✔
Use generics the mathematical operations methods and consider using generic constraints (requires .NET 7.0)✔

Fundamentals

Place all shared project properties into a Directory.Build.props file.
Place all shared project items into a Directory.Build.targets file. (optional)
nullable reference types is enabled ✔
Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
Set LangVersion and the TargetFramework to the latest released versions available (preview versions optional) ✔
and enabled .NET analyzers for both projects ✔
For this assignment, always use Assert.AreEqual() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔

Only issues here is the build, I'll provide more info in my next comment

@Hellothereyoko
Copy link

There's an issue with restoring your dependancies:

Run dotnet restore
Determining projects to restore...
/usr/share/dotnet/sdk/9.0.306/NuGet.targets(186,5): error : Invalid framework identifier ''. [/home/runner/work/EWU-CSCD371-2025-Fall/EWU-CSCD371-2025-Fall/Calculate.slnx]
Error: Process completed with exit code 1.

This means there might be a misconfig with your .sln... I would recommend deleting it and having your IDE regen it; from there restore, build env, and then it should be fixed. Reach out to me on discord if you need any additional assistance. :)

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

Summary

Summary
Generated on: 11/07/2025 - 04:45:03
Coverage date: 11/07/2025 - 04:45:00
Parser: MultiReport (2x Cobertura)
Assemblies: 2
Classes: 3
Files: 3
Line coverage: 94.7% (72 of 76)
Covered lines: 72
Uncovered lines: 4
Coverable lines: 76
Total lines: 128
Branch coverage: 84.3% (27 of 32)
Covered branches: 27
Total branches: 32
Method coverage: Feature is only available for sponsors
Tag: 402_19158469358

Coverage

Calculate - 94.5%
Name Line Branch
Calculate 94.5% 84.3%
Calculate.Calculator 92.1% 80.7%
Calculate.Program 100% 100%
ConsoleUtilities - 100%
Name Line Branch
ConsoleUtilities 100% ****
ConsoleUtilities.ProgramBase 100%

Copy link
Collaborator

@Joshua-Lester3 Joshua-Lester3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instructions

  • Create a Console project called "Calculate". ✔
  • Define a Program Class
    • Define two init-only setter properties, WriteLine and ReadLine, that contain delegates for writing a line of text and reading a line of text respectively ✔
    • Write a test that sets these properties at construction time and then invokes the properties and verifies the expected behavior occurs. ✔
    • Set the default behavior for the WriteLine and ReadLine properties to invoke System.Console versions of the methods and add an empty default constructor. ✔
  • Define a Calculator class ✔
    • Define static Add, Subtract, Multiply, and Divide methods that have two parameters and return a third parameter. ❌ Nitpicky, but I'd interpret this requirement as the 'returned param' is a third out parameter, to make a third parameter.
    • Define a read-only property, MathematicalOperations, of type System.Collections.Generics.IReadOnlyDictionary<TKey,TValue> that:
      • is initialized to a System.Collections.Generics.Dictionary<<TKey,TValue> instance that. ✔
        • Uses char for the key corresponding to the operators +, -, *, and /. ✔
        • Has values that correspond with the Add, Subtract, Multiply, and Divide methods. ✔
    • Implement a TryCalculate method following "TryParse" pattern ✔
      • Valid calculation expressions include such strings as "3 + 4", "42 - 2", etc. ✔
      • If there is no whitespace around the operator, you can assume the calculation is invalid and return false. Similarly if the operands are not integers. ✔
      • Use string.Split(), pattern matching, logical and operators to parse the string in their entirety ✔
      • Index into the MathematicalOperations method using the operator parsed during pattern matching to find the corresponding implementation and invoke it. ✔
  • Implement the Program class to instantiate the calculator and invoke it based on user input from the console. ✔
  • Be sure to use the WriteLine/ReadLine properties on Program for testing the input and output of your program. ✔

Extra Credit

Do one of the following two options (or both if you want extra, extra credit) :)

  • Refactor the redirect portion of the Program class into 'ProgramBase` ✔
    • Move ProgramBase into a ConsoleUtilities assembly to be used in other console-based projects
  • Use generics the mathematical operations methods and consider using generic constraints (requires .NET 7.0) ✔

Fundamentals

  • Place all shared project properties into a Directory.Build.props file.
  • Place all shared project items into a Directory.Build.targets file. (optional)
  • nullable reference types is enabled ✔
  • Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
  • Set LangVersion and the TargetFramework to the latest released versions available (preview versions optional) ✔
  • and enabled .NET analyzers for both projects ✔
  • For this assignment, always use Assert.AreEqual<T>() (the generic version) ✔
  • All of the above should be unit tested ✔
  • Choose simplicity over complexity ✔


public class Calculator
{
public static T Add<T>(T a, T b) where T : INumber<T> => a + b;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This implementation works fine - but doesn't strictly follow a requirement. Ex:

public static void Add<T>(T a, T b, out T result)

/// </summary>
private static string RunProgramWithInput(string input)
{
lock (ConsoleLock)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment about why you added a lock statement. Without running the tests it's hard for the reader to understand why this is necessary. I'm assuming this solves some problem but it's unclear what.


char op = opTemp[0];

var operations = MathematicalOperations<T>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the instructions it mentions to "Index into the MathematicalOperations method using the operator parsed during pattern matching to find the corresponding implementation and invoke it."

if (!operations.TryGetValue(op, out var operation))
return false;

if (op == '/' && right == T.Zero)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the MathematicalOperations division key instead of hard coding this here.

namespace Calculate.Tests;

[TestClass]
public class CalculatorTests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding tests for the Add, Subtract, Multiply, and Divide methods

Copy link

@quattro004 quattro004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Hellothereyoko
Copy link

Instructions

Create a Console project called "Calculate.". ✔
Define a Program Class ✔
Define two init-only setter properties, WriteLine and ReadLine, that contain delegates for writing a line of text and reading a line of text respectively ✔
Write a test that sets these properties at construction time and then invokes the properties and verifies the expected behavior occurs. ✔
Set the default behavior for the WriteLine and ReadLine properties to invoke System.Console versions of the methods and add an empty default constructor. ✔
Define a Calculator class ✔
Define static Add, Subtract, Multiple, and Divide methods that have two parameters and return a third parameter. ✔
Define a read-only property, MathematicalOperations, of type System.Collections.Generics.IReadOnlyDictionary<TKey,TValue> that:
is initialized to a System.Collections.Generics.Dictionary<<TKey,TValue> instance that. ✔
Uses char for the key corresponding to the operators +, -, *, and /. ✔
Has values that correspond with the Add, Subtract, Multiple, and Divide methods. ✔
Implement a TryCalculate method following "TryParse" pattern ✔
Valid calculation expressions include such strings as "3 + 4", "42 - 2", etc. ✔
If there is no whitespace around the operator, you can assume the calculation is invalid and return false. Similarly if the operands are not integers. ✔
Use string.Split(), pattern matching, logical and operators to parse the string in their entirety ✔
Index into the MathematicalOperations method using the operator parsed during pattern matching to find the corresponding implementation and invoke it. ✔
Implement the Program class to instantiate the calculator and invoke it based on user input from the console. ✔
Be sure to use the WriteLine/ReadLine properties on Program for testing the input and output of your program. ✔

Extra Credit

Refactor the redirect portion of the Program class into 'ProgramBase`✔
Move ProgramBase into a ConsoleUtilities assembly to be used in other console-based projects ✔
Use generics the mathematical operations methods and consider using generic constraints (requires .NET 7.0)✔

Fundamentals

Place all shared project properties into a Directory.Build.props file.
Place all shared project items into a Directory.Build.targets file. (optional)
nullable reference types is enabled ✔
Ensure that you turn on code analysis for all projects(EnableNETAnalyzers) ✔
Set LangVersion and the TargetFramework to the latest released versions available (preview versions optional) ✔
and enabled .NET analyzers for both projects ✔
For this assignment, always use Assert.AreEqual() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔

Looks good guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants