-
Notifications
You must be signed in to change notification settings - Fork 21
Assignment6 #78
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
base: Assignment6-LambdaExpressions
Are you sure you want to change the base?
Assignment6 #78
Conversation
…gram. Did so using simple tdd. Tested basic functionality of calculator.
…bjectives to be all good to go!
…eneric constraints
There was a problem hiding this 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!
ulises-aguilar
left a comment
There was a problem hiding this 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. ✔
|
Create a Console project called "Calculate.". ✔ Extra Credit Refactor the redirect portion of the Program class into 'ProgramBase`✔ Fundamentals Place all shared project properties into a Directory.Build.props file. Only issues here is the build, I'll provide more info in my next comment |
|
There's an issue with restoring your dependancies: Run dotnet restore 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. :) |
9da5a9a to
72bd988
Compare
SummarySummary
CoverageCalculate - 94.5%
ConsoleUtilities - 100%
|
Joshua-Lester3
left a comment
There was a problem hiding this 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,
WriteLineandReadLine, 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
WriteLineandReadLineproperties to invokeSystem.Consoleversions of the methods and add an empty default constructor. ✔
- Define two init-only setter properties,
- Define a Calculator class ✔
- Define static
Add,Subtract,Multiply, andDividemethods 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 typeSystem.Collections.Generics.IReadOnlyDictionary<TKey,TValue>that:- is initialized to a
System.Collections.Generics.Dictionary<<TKey,TValue>instance that. ✔- Uses
charfor the key corresponding to the operators +, -, *, and /. ✔ - Has values that correspond with the Add, Subtract, Multiply, and Divide methods. ✔
- Uses
- is initialized to a
- Implement a
TryCalculatemethod following "TryParse" pattern ✔- Valid
calculationexpressions include such strings as "3 + 4", "42 - 2", etc. ✔ - If there is no whitespace around the operator, you can assume the
calculationis 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
MathematicalOperationsmethod using the operator parsed during pattern matching to find the corresponding implementation and invoke it. ✔
- Valid
- Define static
- Implement the Program class to instantiate the calculator and invoke it based on user input from the console. ✔
- Be sure to use the
WriteLine/ReadLineproperties onProgramfor 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
Programclass 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.propsfile. - Place all shared project items into a
Directory.Build.targetsfile. (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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
quattro004
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
|
Instructions Create a Console project called "Calculate.". ✔ Extra Credit Refactor the redirect portion of the Program class into 'ProgramBase`✔ Fundamentals Place all shared project properties into a Directory.Build.props file. Looks good guys! |
Worked with @JosephPotapenko. We implemented both Extra credits