-
Notifications
You must be signed in to change notification settings - Fork 0
Homework 8 - [Calc]
#8
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
6 commits
Select commit
Hold shift + click to select a range
e5445bb
Homework 8 - Calc
ilya-krivtsov 7a1a9b2
Typo fix (hw8 - calc)
ilya-krivtsov 2b8dcd3
Prevent double decimal point (hw8 - calc)
ilya-krivtsov f53e676
Moved tests (hw8 - calc)
ilya-krivtsov d9c9160
Pressing equals after first operand changes state (hw8 - calc)
ilya-krivtsov 3eec5b5
More tests (hw8 - calc)
ilya-krivtsov 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <IsTestProject>true</IsTestProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector" Version="6.0.2" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> | ||
| <PackageReference Include="NUnit" Version="4.2.2" /> | ||
| <PackageReference Include="NUnit.Analyzers" Version="4.4.0" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="NUnit.Framework" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../Calc/Calc.csproj"/> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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,56 @@ | ||
| // <copyright file="CalcErrorTests.cs" company="Ilya Krivtsov"> | ||
| // Copyright (c) Ilya Krivtsov. All rights reserved. | ||
| // </copyright> | ||
|
|
||
| namespace Calc.Tests; | ||
|
|
||
| public class CalcErrorTests | ||
| { | ||
| private Calc calc; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| calc = new(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_0_Divide_0_Gives_Error() | ||
| { | ||
| calc.EnterDigit(0); | ||
| calc.OperatorPressed(ArithmeticOperation.Division); | ||
| calc.EnterDigit(0); | ||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_Error_State_Persists() | ||
| { | ||
| calc.EnterDigit(0); | ||
| calc.OperatorPressed(ArithmeticOperation.Division); | ||
| calc.EnterDigit(0); | ||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| calc.EnterDecimalPoint(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| calc.EnterDigit(4); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_Error_IsRemoved_AfterClear() | ||
| { | ||
| calc.EnterDigit(0); | ||
| calc.OperatorPressed(ArithmeticOperation.Division); | ||
| calc.EnterDigit(0); | ||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("Error")); | ||
| calc.Clear(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0")); | ||
| } | ||
| } | ||
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,145 @@ | ||
| // <copyright file="CalcTests.cs" company="Ilya Krivtsov"> | ||
| // Copyright (c) Ilya Krivtsov. All rights reserved. | ||
| // </copyright> | ||
|
|
||
| namespace Calc.Tests; | ||
|
|
||
| public class CalcTests | ||
| { | ||
| private Calc calc; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| calc = new(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_2_Plus_3_Equals_5() | ||
| { | ||
| calc.EnterDigit(2); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
|
|
||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
|
|
||
| calc.EnterDigit(3); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("3")); | ||
|
|
||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("5")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_2_Plus_3_Minus_10_Equals_Minus_5() | ||
| { | ||
| calc.EnterDigit(2); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
|
|
||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
|
|
||
| calc.EnterDigit(3); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("3")); | ||
|
|
||
| calc.OperatorPressed(ArithmeticOperation.Subtraction); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("5")); | ||
|
|
||
| calc.EnterDigit(1); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("1")); | ||
| calc.EnterDigit(0); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("10")); | ||
|
|
||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("-5")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_0_Point_1_Plus_0_Point_2_Equals_0_Point_3() | ||
| { | ||
| calc.EnterDigit(0); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0")); | ||
| calc.EnterDecimalPoint(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0.")); | ||
| calc.EnterDigit(1); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0.1")); | ||
|
|
||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0.1")); | ||
|
|
||
| calc.EnterDigit(0); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0")); | ||
| calc.EnterDecimalPoint(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0.")); | ||
| calc.EnterDigit(2); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0.2")); | ||
|
|
||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0.3")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_Clear() | ||
| { | ||
| calc.EnterDigit(2); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
|
|
||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
|
|
||
| calc.EnterDigit(3); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("3")); | ||
|
|
||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("5")); | ||
|
|
||
| calc.Clear(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0")); | ||
|
|
||
| calc.EnterDigit(3); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("3")); | ||
|
|
||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("3")); | ||
|
|
||
| calc.EnterDigit(4); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("4")); | ||
|
|
||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("7")); | ||
|
|
||
| calc.Clear(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("0")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_DoubleDecimalPoint_DoesNotAddNew_DecimalPoint() | ||
| { | ||
| calc.EnterDigit(2); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
| calc.EnterDecimalPoint(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2.")); | ||
| calc.EnterDecimalPoint(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2.")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Test_EnteringDigitsAfter_Equals_SetsResultTo_ThatDigit() | ||
| { | ||
| calc.EnterDigit(2); | ||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("2")); | ||
| calc.EnterDigit(5); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("5")); | ||
|
|
||
| calc.Clear(); | ||
|
|
||
| calc.EnterDigit(1); | ||
| calc.OperatorPressed(ArithmeticOperation.Addition); | ||
| calc.EnterDigit(2); | ||
| calc.EqualsPressed(); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("3")); | ||
| calc.EnterDigit(5); | ||
| Assert.That(calc.DisplayResult, Is.EqualTo("5")); | ||
| } | ||
| } |
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,11 @@ | ||
| // <copyright file="GlobalSuppressions.cs" company="Ilya Krivtsov"> | ||
| // Copyright (c) Ilya Krivtsov. All rights reserved. | ||
| // </copyright> | ||
|
|
||
| // This file is used by Code Analysis to maintain SuppressMessage | ||
| // attributes that are applied to this project. | ||
| // Project-level suppressions either have no target or are given | ||
| // a specific target and scoped to a namespace, type, member, etc. | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "This is tests project")] |
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,10 @@ | ||
| <Application xmlns="https://github.com/avaloniaui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| x:Class="Calc.UI.App" | ||
| RequestedThemeVariant="Default"> | ||
| <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --> | ||
|
|
||
| <Application.Styles> | ||
| <FluentTheme /> | ||
| </Application.Styles> | ||
| </Application> |
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,27 @@ | ||
| // <copyright file="App.axaml.cs" company="Ilya Krivtsov"> | ||
| // Copyright (c) Ilya Krivtsov. All rights reserved. | ||
| // </copyright> | ||
|
|
||
| namespace Calc.UI; | ||
|
|
||
| using Avalonia; | ||
| using Avalonia.Controls.ApplicationLifetimes; | ||
| using Avalonia.Markup.Xaml; | ||
|
|
||
| public partial class App : Application | ||
| { | ||
| public override void Initialize() | ||
| { | ||
| AvaloniaXamlLoader.Load(this); | ||
| } | ||
|
|
||
| public override void OnFrameworkInitializationCompleted() | ||
| { | ||
| if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
| { | ||
| desktop.MainWindow = new MainWindow(); | ||
| } | ||
|
|
||
| base.OnFrameworkInitializationCompleted(); | ||
| } | ||
| } |
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,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>WinExe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <BuiltInComInteropSupport>true</BuiltInComInteropSupport> | ||
| <ApplicationManifest>app.manifest</ApplicationManifest> | ||
| <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Avalonia" Version="11.2.7" /> | ||
| <PackageReference Include="Avalonia.Desktop" Version="11.2.7" /> | ||
| <PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.7" /> | ||
| <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.7" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../Calc/Calc.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
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,16 @@ | ||
| // <copyright file="GlobalSuppressions.cs" company="Ilya Krivtsov"> | ||
| // Copyright (c) Ilya Krivtsov. All rights reserved. | ||
| // </copyright> | ||
|
|
||
| // This file is used by Code Analysis to maintain SuppressMessage | ||
| // attributes that are applied to this project. | ||
| // Project-level suppressions either have no target or are given | ||
| // a specific target and scoped to a namespace, type, member, etc. | ||
| using System.Diagnostics.CodeAnalysis; | ||
|
|
||
| [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Entry point", Scope = "type", Target = "~T:Calc.UI.Program")] | ||
|
|
||
| [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601:Partial elements should be documented", Justification = "Application class", Scope = "type", Target = "~T:Calc.UI.App")] | ||
| [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601:Partial elements should be documented", Justification = "Window class", Scope = "type", Target = "~T:Calc.UI.MainWindow")] | ||
| [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Application class", Scope = "type", Target = "~T:Calc.UI.App")] | ||
| [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Window class", Scope = "type", Target = "~T:Calc.UI.MainWindow")] |
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,47 @@ | ||
| <Window xmlns="https://github.com/avaloniaui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| mc:Ignorable="d" d:DesignWidth="512" d:DesignHeight="640" | ||
| x:Class="Calc.UI.MainWindow" | ||
| Width="512" Height="640" CanResize="false"> | ||
|
|
||
| <Grid x:Name="buttonsGrid"> | ||
| <Grid.ColumnDefinitions> | ||
| <ColumnDefinition Width="*"></ColumnDefinition> | ||
| <ColumnDefinition Width="*"></ColumnDefinition> | ||
| <ColumnDefinition Width="*"></ColumnDefinition> | ||
| <ColumnDefinition Width="*"></ColumnDefinition> | ||
| </Grid.ColumnDefinitions> | ||
| <Grid.RowDefinitions> | ||
| <RowDefinition Height="120"></RowDefinition> | ||
| <RowDefinition Height="*"></RowDefinition> | ||
| <RowDefinition Height="*"></RowDefinition> | ||
| <RowDefinition Height="*"></RowDefinition> | ||
| <RowDefinition Height="*"></RowDefinition> | ||
| <RowDefinition Height="*"></RowDefinition> | ||
| </Grid.RowDefinitions> | ||
|
|
||
| <Label x:Name="resultText" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" FontSize="80" Content="0" | ||
| HorizontalContentAlignment="Right" VerticalContentAlignment="Center"/> | ||
|
|
||
| <Button Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Content="0" FontSize="48" Margin="4" Click="OnZero" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
| <Button Grid.Row="5" Grid.Column="2" Content="." FontSize="48" Margin="4" Click="OnDecimal" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
|
|
||
| <Button Grid.Row="1" Grid.Column="0" Content="C" FontSize="48" Margin="4" Click="OnClear" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
| <Button Grid.Row="1" Grid.Column="1" Content="÷" FontSize="48" Margin="4" Click="OnOperator" Tag="Division" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
| <Button Grid.Row="1" Grid.Column="2" Content="×" FontSize="48" Margin="4" Click="OnOperator" Tag="Multiplication" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
| <Button Grid.Row="1" Grid.Column="3" Content="-" FontSize="48" Margin="4" Click="OnOperator" Tag="Subtraction" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
|
|
||
| <Button Grid.Row="2" Grid.Column="3" Grid.RowSpan="2" Content="+" FontSize="48" Margin="4" Click="OnOperator" Tag="Addition" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
| <Button Grid.Row="4" Grid.Column="3" Grid.RowSpan="2" Content="=" FontSize="48" Margin="4" Click="OnEquals" | ||
| HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> | ||
| </Grid> | ||
| </Window> |
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.