Skip to content

Conversation

@KorbinWeiler
Copy link

Worked with @BillMillerCoding

Copy link

@Al3xramirez Al3xramirez 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. ❌ (Must have 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. ✔

Fundamentals
Place all shared project properties into a Directory.Build.props file.✔
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) ❌(Not all Asserts use this)
All of the above should be unit tested ❌ Should add more code coverage
Choose simplicity over complexity ✔

Copy link

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

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! I think you're just missing some unit tests on your operator functions. :)

@kellanburns
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, 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 ✔

Code looks good, I'd just unit test the operands more. For example, I'd test for the DivideByZeroException in the divide method, and I'd refactor your Main to call a function that handles the user-input-loop and allows you to test it.

Choose a reason for hiding this comment

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

You could add an additional test for dividing by zero in here.

Choose a reason for hiding this comment

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

Added :)

@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. ✔
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 ❌(not all cases covered across Program and Calculator)
• Choose simplicity over complexity ✔

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

Summary

Summary
Generated on: 11/07/2025 - 04:59:01
Coverage date: 11/07/2025 - 04:58:59
Parser: MultiReport (2x Cobertura)
Assemblies: 1
Classes: 2
Files: 2
Line coverage: 70% (49 of 70)
Covered lines: 49
Uncovered lines: 21
Coverable lines: 70
Total lines: 111
Branch coverage: 66.6% (12 of 18)
Covered branches: 12
Total branches: 18
Method coverage: Feature is only available for sponsors
Tag: 403_19158674206

Coverage

Calculate - 70%
Name Line Branch
Calculate 70% 66.6%
Calculate.Calculator 90.6% 85.7%
Calculate.Program 37% 0%

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: doesn't return third 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. ✔
    • 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. ❌ Not tested.

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 ❌ Doesn't seem to be all unit tested. Code coverage report alerts this, but it looks like most of the testing needs to be done in Program.Main
  • Choose simplicity over complexity ✔

@@ -0,0 +1,46 @@
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using Microsoft.VisualBasic;
Copy link

@quattro004 quattro004 Nov 9, 2025

Choose a reason for hiding this comment

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

Is this (Microsoft.VisualBasic) being used?

{
ReadLine = readLine;
WriteLine = writeLine;
}

Choose a reason for hiding this comment

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

I'm curious about the intention here as the instructions mention "Set the default behavior for the WriteLine and ReadLine properties to invoke System.Console versions of the methods". This makes me think I could use something other than the system defined versions.

program.WriteLine("Enter a calculation (e.g.,3 + 4), or blank to quit");

string? input;
while (!string.IsNullOrWhiteSpace(input = program.ReadLine()))

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.

return (double)a / b;
}

public bool TryCalculate(string? expression, out double answer)

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."

}

[Fact]
public void TryCalculate_InvalidInput_ReturnsFalse()

Choose a reason for hiding this comment

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

I wonder if a Theory with inline data would work here? nit: Typically you want only a single assertion for each unit test.

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.

Keep up the good work!

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.

8 participants