Skip to content

Conversation

@katmilton
Copy link

@katmilton katmilton commented Nov 4, 2025

I worked with @steeley21. We implemented both extra credit options.

Copy link

@ColtonKnopik ColtonKnopik 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. ✔

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 ✔

Stellar!

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Summary

Summary
Generated on: 11/05/2025 - 20:45:07
Coverage date: 11/05/2025 - 20:45:05
Parser: MultiReport (2x Cobertura)
Assemblies: 2
Classes: 4
Files: 4
Line coverage: 93.8% (61 of 65)
Covered lines: 61
Uncovered lines: 4
Coverable lines: 65
Total lines: 172
Branch coverage: 94.1% (32 of 34)
Covered branches: 32
Total branches: 34
Method coverage: Feature is only available for sponsors
Tag: 372_19115761889

Coverage

Calculate - 92.4%
Name Line Branch
Calculate 92.4% 93.3%
Calculate.Calculator 100%
Calculate.Calculator`1 86.2% 91.6%
Calculate.Program 100% 100%
ConsoleUtilities - 100%
Name Line Branch
ConsoleUtilities 100% 100%
ConsoleUtilities.ProgramBase 100% 100%

Copy link

@chanderlud chanderlud 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, 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

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 ✔

@JosephPotapenko
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
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() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔

@JosephPotapenko
Copy link

Looks good. Not sure you are implementing all of the "using" statements, but other than that- I think it's great.

@c-stanton
Copy link

• Create a Console project called "Calculate.". ✔
• Define a Program Class
o 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 ✔
o Write a test that sets these properties at construction time and then invokes the properties and verifies the expected behavior occurs. ✔
o 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 ✔
o Define static Add, Subtract, Multiple, and Divide methods that have two parameters and return a third parameter. ✔
o 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. ✔
o 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() (the generic version) ✔
• All of the above should be unit tested ✔
• Choose simplicity over complexity ✔

Nice work!

@BillMillerCoding
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
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() (the generic version) ✔
All of the above should be unit tested ✔
Choose simplicity over complexity ✔

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. ❌ nit: should have third parameter, possibly an 'out' param
    • 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. ❌ Creates new lambdas - doesn't reuse these 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 ✔

Comment on lines +20 to +31
['+'] = (a, b) => a + b,
['-'] = (a, b) => a - b,
['*'] = (a, b) => a * b,
['/'] = (a, b) => a / b
};

}

public T Add(T a, T b) => a + b;
public T Subtract(T a, T b) => a - b;
public T Multiply(T a, T b) => a * b;
public T Divide(T a, T b) => 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.

You can reference the method name here, instead of creating another delegate/lambda. Good to refactor and reduce repeated code.

/// <returns>0 for normal exit, non-zero for abnormal termination.</returns>
public int Run()
{
while (true)

Choose a reason for hiding this comment

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

Consider that having an infinite loop creates a certain kind of interactive experience like a REPL vs if you did not have the loop the app would exit on each invocation and could be used like in an automated tool call fashion.

var read2 = program.ReadLine(); //will return null

// Assert
Assert.AreEqual<int>(1, writes.Count);

Choose a reason for hiding this comment

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

nit: Unit tests should typically have a single assertion in order to keep them focused and so you know it fails for a specific reason.


var op = parts[1][0];

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

Choose a reason for hiding this comment

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

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

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, love all the tests!

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.

9 participants