Compare commits
14 Commits
cfe68e39cc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b7a9f0cfc2 | |||
| dd3cff0eaa | |||
| a08838bb8b | |||
| 595c02231c | |||
| 44ddb1fbec | |||
| 19a1ddb334 | |||
| 7cf49a5a1b | |||
| c9447cebdf | |||
| 4ebb81c211 | |||
| 04d258c5a3 | |||
| bf2c734baf | |||
| 86b9afe02f | |||
| e8959b9498 | |||
| c7eda63c03 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
||||
[submodule "FusionCalculator"]
|
||||
path = FusionCalculator
|
||||
url = https://github.com/Timerix22/FusionCalculator.git
|
||||
url = https://timerix.ddns.net/git/Timerix/FusionCalculator.git
|
||||
|
||||
Submodule FusionCalculator updated: 2a4f92fe35...d83106358f
10
README.md
10
README.md
@@ -2,12 +2,20 @@
|
||||
A calculator application written in C# and Fusion.
|
||||
Using Avalonia to draw GUI.
|
||||
|
||||
You can just type expression if tou don't like pressing GUI buttons.
|
||||
|
||||
**Key binds:**
|
||||
- `Enter`: `=`
|
||||
- `Del`: `AC`
|
||||
|
||||

|
||||
|
||||
## Building
|
||||
Requirements: git, bash, [dotnet8](https://dotnet.microsoft.com/en-us/download/dotnet/8.0), [fut](https://github.com/fusionlanguage/fut)
|
||||
|
||||
1. ensure that [FusionCalculator](https://github.com/Timerix22/FusionCalculator) submodule is up-to-date.
|
||||
```shell
|
||||
git submodule init && git submodule update
|
||||
it submodule update --init
|
||||
```
|
||||
2. Translate FusionCalculator to C#
|
||||
```shell
|
||||
|
||||
@@ -3,6 +3,31 @@
|
||||
x:Class="SharpCalculator.Avalonia.App"
|
||||
RequestedThemeVariant="Dark">
|
||||
<Application.Styles>
|
||||
|
||||
<SimpleTheme />
|
||||
|
||||
<Style Selector="Control.center">
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Button.button">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="Margin" Value="1"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Button.gray">
|
||||
<Setter Property="Background" Value="Gray"/>
|
||||
</Style>
|
||||
|
||||
<Style Selector="Button.orange">
|
||||
<Setter Property="Background" Value="#C07500"/>
|
||||
</Style>
|
||||
|
||||
</Application.Styles>
|
||||
</Application>
|
||||
@@ -1,4 +1,9 @@
|
||||
using Avalonia;
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Globalization;
|
||||
global using Avalonia;
|
||||
global using Avalonia.Controls;
|
||||
global using Avalonia.Interactivity;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
|
||||
@@ -1,571 +1,176 @@
|
||||
<Window
|
||||
FontFamily="Consolas"
|
||||
FontSize="24"
|
||||
Height="750"
|
||||
Title="SharpCalculator"
|
||||
Width="600"
|
||||
mc:Ignorable="d"
|
||||
x:Class="SharpCalculator.Avalonia.MainWindow"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ag="clr-namespace:AvaloniaAutoGrid;assembly=AvaloniaAutoGrid"
|
||||
x:Class="SharpCalculator.Avalonia.MainWindow"
|
||||
Title="SharpCalculator"
|
||||
Icon="avares://SharpCalculator.Avalonia/assets/icon.ico"
|
||||
FontFamily="Consolas" FontSize="24"
|
||||
MinWidth="460" MinHeight="570"
|
||||
Width="460" Height="570">
|
||||
|
||||
<Grid
|
||||
HorizontalAlignment="Center"
|
||||
Margin="20"
|
||||
VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>* * * * * * *</Grid.ColumnDefinitions>
|
||||
<!-- ReSharper disable Xaml.MissingGridIndex -->
|
||||
<ag:AutoGrid Margin="10"
|
||||
ColumnDefinitions="*"
|
||||
RowDefinitions="1* 40 1* 330">
|
||||
<TextBox Name="Input"
|
||||
TextChanged="Input_OnTextChanged"
|
||||
BorderThickness="2"
|
||||
BorderBrush="#AAAAAA"
|
||||
TextWrapping="Wrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"/>
|
||||
|
||||
<Grid.RowDefinitions>* * * * * * * * * *</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock VerticalAlignment="Center"
|
||||
Foreground="#AAAAAA"
|
||||
Text="="/>
|
||||
<TextBox Name="Output"
|
||||
Margin="16 0 0 0"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
IsReadOnly="True"
|
||||
BorderThickness="0"
|
||||
TextWrapping="NoWrap"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- 1st row -->
|
||||
<TextBox Name="History"
|
||||
Foreground="Gray"
|
||||
BorderThickness="1"
|
||||
BorderBrush="Gray"
|
||||
IsReadOnly="True"
|
||||
TextWrapping="NoWrap"
|
||||
FontSize="18"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"/>
|
||||
|
||||
<TextBlock
|
||||
FontSize="40"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="1"
|
||||
HorizontalAlignment="Right"
|
||||
Name="Input"
|
||||
Text="" />
|
||||
<!-- ReSharper disable once Xaml.MissingGridIndex -->
|
||||
<ag:AutoGrid
|
||||
ColumnDefinitions="*"
|
||||
RowDefinitions="*"
|
||||
ColumnCount="7" RowCount="5"
|
||||
VerticalAlignment="Bottom"
|
||||
MinWidth="440" MaxWidth="440"
|
||||
MinHeight="320" MaxHeight="320">
|
||||
|
||||
<!-- 2nd row -->
|
||||
<!-- 1st row -->
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="ClearButton_OnClick"
|
||||
Content="AC"
|
||||
Grid.Column="0"
|
||||
Grid.Row="2"
|
||||
Name="ClearButton"/>
|
||||
<Button Classes="button gray"
|
||||
Click="ClearButton_OnClick" Content="AC"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="("
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content=")"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="/"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="("/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="^"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content=")" />
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="sin"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button orange"
|
||||
Click="MathButton_OnClick" Content="/"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="asin"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="2"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="1/x"/>
|
||||
|
||||
<!-- 3rd row -->
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="sin"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="7"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="asin"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="8"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="9"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="*"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<!-- 2nd row -->
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="e"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="7"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="cos"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="8"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="acos"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="3"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="9"/>
|
||||
|
||||
<!-- 4th row -->
|
||||
<Button Classes="button orange"
|
||||
Click="MathButton_OnClick" Content="*"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="4"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="^"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="5"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="cos"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="6"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="acos"/>
|
||||
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="-"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<!-- 3th row -->
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="10^x"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="4"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="tan"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="5"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="atan"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="4"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="6"/>
|
||||
|
||||
<!-- 5th row -->
|
||||
<Button Classes="button orange"
|
||||
Click="MathButton_OnClick" Content="-"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="1"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
FontSize="22"
|
||||
Click="MathButton_OnClick" Content="10^x"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="2"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="tg"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="3"
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="atg"/>
|
||||
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="MathButton_OnClick"
|
||||
Content="+"
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<!-- 4th row -->
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="rand"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="1"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="ctg"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="2"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="actg"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="5"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="3"/>
|
||||
|
||||
<!-- 6th row -->
|
||||
<Button Classes="button orange"
|
||||
Click="MathButton_OnClick" Content="+"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="0"
|
||||
CornerRadius="30"
|
||||
Grid.Column="0"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="e"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="%"
|
||||
CornerRadius="30"
|
||||
Grid.Column="1"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="ctg"/>
|
||||
|
||||
<Button
|
||||
Click="MathButton_OnClick"
|
||||
Content="."
|
||||
CornerRadius="30"
|
||||
Grid.Column="2"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="actg"/>
|
||||
|
||||
<Button
|
||||
Background="Orange"
|
||||
Click="ResultButton_OnClick"
|
||||
Content="="
|
||||
CornerRadius="30"
|
||||
Grid.Column="3"
|
||||
Grid.Row="6"
|
||||
Height="55"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<!-- 5th row -->
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="π"
|
||||
CornerRadius="30"
|
||||
Grid.Column="4"
|
||||
Grid.Row="6"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="0"/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="1/x"
|
||||
CornerRadius="30"
|
||||
Grid.Column="5"
|
||||
Grid.Row="6"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="."/>
|
||||
|
||||
<Button
|
||||
Background="Gray"
|
||||
Click="MathButton_OnClick"
|
||||
Content="log"
|
||||
CornerRadius="30"
|
||||
Grid.Column="6"
|
||||
Grid.Row="6"
|
||||
Height="60"
|
||||
HorizontalAlignment="Center"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="5"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Width="60" />
|
||||
<Button Classes="button"
|
||||
Click="MathButton_OnClick" Content="%"/>
|
||||
|
||||
<!-- 7th row -->
|
||||
<Button Classes="button orange"
|
||||
Click="ResultButton_OnClick" Content="="/>
|
||||
|
||||
<TextBlock
|
||||
FontSize="25"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="7"
|
||||
Name="History1"
|
||||
Text="" />
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="π"/>
|
||||
|
||||
<!-- 8th row -->
|
||||
<Button Classes="button gray"
|
||||
FontSize="22"
|
||||
Click="MathButton_OnClick" Content="rand"/>
|
||||
|
||||
<TextBlock
|
||||
FontSize="25"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="8"
|
||||
Name="History2"
|
||||
Text="" />
|
||||
|
||||
<!-- 9th row -->
|
||||
|
||||
<TextBlock
|
||||
FontSize="25"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="7"
|
||||
Grid.Row="9"
|
||||
Name="History3"
|
||||
Text="" />
|
||||
</Grid>
|
||||
<Button Classes="button gray"
|
||||
Click="MathButton_OnClick" Content="ln"/>
|
||||
</ag:AutoGrid>
|
||||
</ag:AutoGrid>
|
||||
</Window>
|
||||
@@ -1,129 +1,125 @@
|
||||
// This implementation of the calculator using
|
||||
// multi-translating programming language Fusion.
|
||||
// The main logic was written on the Fusion,
|
||||
// then retranslated into c#, 'out' module in FusionCalculator
|
||||
// is a translated c# code, that used by SharpCalculator module.
|
||||
// If you want to dive into the logic of the calculator,
|
||||
// you need to check 'out' folder in FusionCalculator module.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Input;
|
||||
using FusionCalculator;
|
||||
using Avalonia.Media;
|
||||
|
||||
|
||||
namespace SharpCalculator.Avalonia;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
static Random _random = new Random(); // Random object for rand() function in calculator
|
||||
double _randomNumber = _random.NextDouble(); // Random variable is between 0 to 1
|
||||
private int _currentIndex = 0; // Current index for checking the length of input text, accordingly for clear button
|
||||
|
||||
private List<string> _history = new List<string>();
|
||||
private readonly Random Random = new();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
// https://github.com/AvaloniaUI/Avalonia/discussions/12179
|
||||
KeyDownEvent.AddClassHandler<TopLevel>(GlobalOnKeyDown, handledEventsToo: true);
|
||||
}
|
||||
|
||||
private void MathButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
private void GlobalOnKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (sender is not Button button) // Checking if button exist, if not throw Exception
|
||||
throw new Exception();
|
||||
|
||||
string text; // declaring text for using it in switch case
|
||||
|
||||
ClearButton.Content = "AC"; // clear button content changing to Accurate Clear mode
|
||||
|
||||
switch (Input.Text) // Switch case for checking the inputting functions
|
||||
switch (e.Key)
|
||||
{
|
||||
case "rand": // rand function add random variable from 0 to 1 into Input
|
||||
Input.Text = "";
|
||||
Input.Text += _randomNumber.ToString(CultureInfo.InvariantCulture);
|
||||
case Key.Enter:
|
||||
CalculateResult();
|
||||
break;
|
||||
case "π": // Pi function add pi value into Input
|
||||
Input.Text = "";
|
||||
Input.Text += "3.1415";
|
||||
break;
|
||||
case "e": // euler function add e value into Input
|
||||
Input.Text = "";
|
||||
Input.Text += "2.71828";
|
||||
break;
|
||||
case "10^x": // ten in power of x function
|
||||
Input.Text = "";
|
||||
Input.Text += "10^";
|
||||
break;
|
||||
case "1/x": // one over x function
|
||||
Input.Text = "";
|
||||
Input.Text += "1/";
|
||||
break;
|
||||
default: // if there is no function input, then just input Button content
|
||||
text = button.Content!.ToString()!;
|
||||
Input.Text += text;
|
||||
case Key.Delete:
|
||||
Clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
private void CalculateResult()
|
||||
{
|
||||
// Checking the indexes and the emptiness of the input for clearing one by one
|
||||
if (Input.Text != "" && _currentIndex < Input.Text!.Length)
|
||||
{
|
||||
if ((string)ClearButton.Content! == "AC") // if clear button content equal to AC, clear one by one
|
||||
{
|
||||
Input.Text = Input.Text.Remove(_currentIndex, 1);
|
||||
_currentIndex++;
|
||||
}
|
||||
else if ((string)ClearButton.Content! == "C") // if clear button content equal to C, clear all
|
||||
{
|
||||
Input.Text = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case when there's no text or all characters are cleared
|
||||
_currentIndex = 0; // Reset the index for the next round
|
||||
}
|
||||
if(Input.Text == null || Output.Text == null || Output.Text.StartsWith("Error"))
|
||||
return;
|
||||
string expression = Input.Text;
|
||||
string result = Output.Text;
|
||||
AppendToHistory($"{expression}={result}");
|
||||
Input.Text = result;
|
||||
}
|
||||
|
||||
private void AppendToHistory(string line) //function of appending expression to the history list
|
||||
{
|
||||
// begin new line if not empty
|
||||
if (!string.IsNullOrEmpty(History.Text))
|
||||
History.Text += '\n';
|
||||
/// add line without space characters
|
||||
History.Text += line
|
||||
.Replace("\t", " ")
|
||||
.Replace("\n", " ")
|
||||
.Replace("\r", " ")
|
||||
.Replace(" ", " ");
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
Input.Clear();
|
||||
Output.Clear();
|
||||
}
|
||||
|
||||
private void ResultButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
History1.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
History2.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
History3.Foreground = new SolidColorBrush(Colors.Gray);
|
||||
CalculateResult();
|
||||
}
|
||||
|
||||
if(Input.Text == null) // checking Input for nullability
|
||||
|
||||
private void ClearButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
private void MathButton_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button)
|
||||
throw new Exception();
|
||||
|
||||
string buttonText = button.Content!.ToString()!; // declaring text for using it in switch case
|
||||
Input.Text += buttonText switch
|
||||
{
|
||||
"rand" => // random number from 0 to 1 into Input
|
||||
Random.NextDouble().ToString("0.#####", CultureInfo.InvariantCulture),
|
||||
"π" => // Pi constant
|
||||
"3.14159",
|
||||
"e" => // E constant
|
||||
"2.71828",
|
||||
"10^x" => // ten in power of x function
|
||||
"10^",
|
||||
"1/x" => // one over x function
|
||||
"1/",
|
||||
"sin" or "cos" or "tg" or "ctg"
|
||||
or "asin" or "acos" or "atg" or "actg"
|
||||
or "ln" => buttonText+'(',
|
||||
_ => buttonText
|
||||
};
|
||||
}
|
||||
|
||||
private void Input_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
if(Input.Text == null)
|
||||
return;
|
||||
string exprStr = Input.Text; // expression variable, for print result
|
||||
|
||||
string exprStr = Input.Text; // mathematical expression
|
||||
try
|
||||
{
|
||||
double rezult = Calculator.Calculate(exprStr); // result being processed by calculator object that implemented in FusionCalculator Module
|
||||
if (!double.IsNaN(rezult))
|
||||
// expression is being processed by Calculator class that implemented in FusionCalculator Module
|
||||
double result = Calculator.Calculate(exprStr);
|
||||
|
||||
// incomplete expression with no rezult
|
||||
if (double.IsNaN(result))
|
||||
Output.Text = "";
|
||||
else if (Math.Abs(result) is >= 10e-5 and <= 10e15)
|
||||
{
|
||||
Input.Text = rezult.ToString(CultureInfo.InvariantCulture);
|
||||
_history.Add(rezult.ToString(CultureInfo.InvariantCulture));
|
||||
// decimal number with 5-digit precision for regular numbers
|
||||
Output.Text = result.ToString("0.#####", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
// scientific notation with 5-digit precision for big and small numbers
|
||||
Output.Text = result.ToString("0.#####E0", CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Input.Text = "Error: "+exception.Message;
|
||||
Output.Text = $"Error: {exception.Message}";
|
||||
}
|
||||
|
||||
// Display the calculation history in the three TextBlocks
|
||||
if (_history.Count > 0)
|
||||
History1.Text = _history[0];
|
||||
if (_history.Count > 1)
|
||||
History2.Text = _history[1];
|
||||
if (_history.Count > 2)
|
||||
History3.Text = _history[2];
|
||||
|
||||
ClearButton.Content = "C"; // if the expression is printed, then change clear button content ot C, for clearing expression totally
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,7 @@
|
||||
using Avalonia;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace SharpCalculator.Avalonia;
|
||||
namespace SharpCalculator.Avalonia;
|
||||
|
||||
class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<ApplicationIcon>assets\icon.ico</ApplicationIcon>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.6" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
|
||||
<PackageReference Include="Avalonia.Themes.Simple" Version="11.0.6" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.6" />
|
||||
<PackageReference Include="Avalonia" Version="11.3.10" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.3.10" />
|
||||
<PackageReference Include="Avalonia.Themes.Simple" Version="11.3.10" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.10" />
|
||||
<PackageReference Include="Russkyc.AvaloniaAutoGrid" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FusionCalculator\FusionCalculator.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AvaloniaResource Include="assets\**"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
BIN
SharpCalculator.Avalonia/assets/icon.ico
Normal file
BIN
SharpCalculator.Avalonia/assets/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
35
SharpCalculator.Tests/ComplicatedExpressionTests.cs
Normal file
35
SharpCalculator.Tests/ComplicatedExpressionTests.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace SharpCalculator.Tests;
|
||||
|
||||
public class ComplicatedExpressionTests
|
||||
{
|
||||
public ComplicatedExpressionTests()
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9,2,3)]
|
||||
public void Expression1(double a, double b, double c) =>
|
||||
Assert.Equal( a/(b+c), Calculator.Calculate($"({a})/(({b})+({c}))"));
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9,2,3)]
|
||||
public void Expression2(double a, double b, double c) =>
|
||||
Assert.Equal( Math.Sin(a)-b*Math.Cos(c),
|
||||
Calculator.Calculate($"sin(({a}))-(({b})*cos(({c})))"),
|
||||
FunctionTests.PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9,2,3)]
|
||||
public void Expression3(double a, double b, double c) =>
|
||||
Assert.Equal( a*Math.Pow(b,c)+a*Math.Pow(b,c+1)+a*Math.Pow(b,c+2),
|
||||
Calculator.Calculate($"({a})*({b})^({c}) + ({a})*({b})^({c+1}) + ({a})*({b})^({c+2})"),
|
||||
FunctionTests.PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9,2,3)]
|
||||
public void Expression4(double a, double b, double c) =>
|
||||
Assert.Equal(a/(b+Math.Tan(c)),
|
||||
Calculator.Calculate($"({a})/(({b})+tan(({c})))"),
|
||||
FunctionTests.PRECISION);
|
||||
}
|
||||
107
SharpCalculator.Tests/FunctionTests.cs
Normal file
107
SharpCalculator.Tests/FunctionTests.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
namespace SharpCalculator.Tests;
|
||||
|
||||
public class FunctionTests
|
||||
{
|
||||
public const int PRECISION = 8;
|
||||
|
||||
public FunctionTests()
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(5)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
[InlineData(Math.PI/4)]
|
||||
[InlineData(Math.PI/2)]
|
||||
[InlineData(Math.PI*3/4)]
|
||||
[InlineData(Math.PI*2)]
|
||||
[InlineData(999)]
|
||||
[InlineData(-999)]
|
||||
public void Sin(double a) =>
|
||||
Assert.Equal(Math.Sin(a), Calculator.Calculate($"sin({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(5)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
[InlineData(Math.PI/4)]
|
||||
[InlineData(Math.PI/2)]
|
||||
[InlineData(Math.PI*3/4)]
|
||||
[InlineData(Math.PI*2)]
|
||||
[InlineData(999)]
|
||||
[InlineData(-999)]
|
||||
public void Cos(double a) =>
|
||||
Assert.Equal(Math.Cos(a), Calculator.Calculate($"cos({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(5)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
[InlineData(Math.PI/4)]
|
||||
[InlineData(Math.PI/1.99)]
|
||||
[InlineData(Math.PI*3/4)]
|
||||
[InlineData(Math.PI*1.99)]
|
||||
[InlineData(999)]
|
||||
[InlineData(-999)]
|
||||
public void Tan(double a) =>
|
||||
Assert.Equal(Math.Tan(a), Calculator.Calculate($"tan({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(5)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
[InlineData(Math.PI/4)]
|
||||
[InlineData(Math.PI/2)]
|
||||
[InlineData(Math.PI*3/4)]
|
||||
[InlineData(Math.PI*1.99)]
|
||||
[InlineData(999)]
|
||||
[InlineData(-999)]
|
||||
public void Ctg(double a) =>
|
||||
Assert.Equal(1 / Math.Tan(a), Calculator.Calculate($"ctg({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
public void Asin(double a) =>
|
||||
Assert.Equal( Math.Asin(a), Calculator.Calculate($"asin({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
public void Acos(double a) =>
|
||||
Assert.Equal( Math.Acos(a), Calculator.Calculate($"acos({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
public void Atan(double a) =>
|
||||
Assert.Equal( Math.Atan(a), Calculator.Calculate($"atan({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
public void Actg(double a) =>
|
||||
Assert.Equal( Math.Atan(1 / a), Calculator.Calculate($"actg({a})"), PRECISION);
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.9)]
|
||||
[InlineData(1)]
|
||||
[InlineData(-3)]
|
||||
[InlineData(-2)]
|
||||
public void Ln(double a) =>
|
||||
Assert.Equal( Math.Log(a), Calculator.Calculate($"ln({a})"), PRECISION);
|
||||
}
|
||||
4
SharpCalculator.Tests/GlobalUsings.cs
Normal file
4
SharpCalculator.Tests/GlobalUsings.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
global using System;
|
||||
global using System.Globalization;
|
||||
global using Xunit;
|
||||
global using FusionCalculator;
|
||||
57
SharpCalculator.Tests/OperatorTests.cs
Normal file
57
SharpCalculator.Tests/OperatorTests.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
namespace SharpCalculator.Tests;
|
||||
|
||||
public class OperatorTests
|
||||
{
|
||||
public OperatorTests()
|
||||
{
|
||||
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(15,5)]
|
||||
[InlineData(13,-6)]
|
||||
[InlineData(-1,-6)]
|
||||
[InlineData(-13,6)]
|
||||
public void Sum(double a,double b) =>
|
||||
Assert.Equal(a+b, Calculator.Calculate($"({a})+({b})"));
|
||||
|
||||
[Theory]
|
||||
[InlineData(15,5)]
|
||||
[InlineData(13,-6)]
|
||||
[InlineData(-1,-6)]
|
||||
[InlineData(-13,6)]
|
||||
public void Subtract(double a,double b) =>
|
||||
Assert.Equal(a-b, Calculator.Calculate($"({a})-({b})"));
|
||||
|
||||
[Theory]
|
||||
[InlineData(15,5)]
|
||||
[InlineData(13,-6)]
|
||||
[InlineData(-1,-6)]
|
||||
[InlineData(-13,6)]
|
||||
public void Multiplying(double a,double b) =>
|
||||
Assert.Equal(a*b, Calculator.Calculate($"({a})*({b})"));
|
||||
|
||||
[Theory]
|
||||
[InlineData(15,5)]
|
||||
[InlineData(24,-6)]
|
||||
[InlineData(-12,-6)]
|
||||
[InlineData(-36,6)]
|
||||
public void Dividing(double a,double b) =>
|
||||
Assert.Equal(a/b, Calculator.Calculate($"({a})/({b})"));
|
||||
|
||||
[Theory]
|
||||
[InlineData(2,5)]
|
||||
[InlineData(1,-1)]
|
||||
[InlineData(-3,-4)]
|
||||
[InlineData(-2,2)]
|
||||
public void Power(double a,double b) =>
|
||||
Assert.Equal(Math.Pow(a,b), Calculator.Calculate($"({a})^({b})"));
|
||||
|
||||
[Theory]
|
||||
[InlineData(5,2)]
|
||||
[InlineData(1,-1)]
|
||||
[InlineData(-3,-2)]
|
||||
[InlineData(-2,2)]
|
||||
public void Mod(double a,double b) =>
|
||||
Assert.Equal( a%b, Calculator.Calculate($"({a})%({b})"));
|
||||
}
|
||||
28
SharpCalculator.Tests/SharpCalculator.Tests.csproj
Normal file
28
SharpCalculator.Tests/SharpCalculator.Tests.csproj
Normal file
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FusionCalculator\FusionCalculator.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -9,8 +9,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution_items", "solution_
|
||||
.gitignore = .gitignore
|
||||
.gitmodules = .gitmodules
|
||||
README.md = README.md
|
||||
build.sh = build.sh
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCalculator.Tests", "SharpCalculator.Tests\SharpCalculator.Tests.csproj", "{E929E48D-D11B-4FB5-AC6F-D0D50E2B3BD1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -25,5 +28,9 @@ Global
|
||||
{8EA39217-DEBD-493B-A19C-5505B58E03FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8EA39217-DEBD-493B-A19C-5505B58E03FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8EA39217-DEBD-493B-A19C-5505B58E03FA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E929E48D-D11B-4FB5-AC6F-D0D50E2B3BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E929E48D-D11B-4FB5-AC6F-D0D50E2B3BD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E929E48D-D11B-4FB5-AC6F-D0D50E2B3BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E929E48D-D11B-4FB5-AC6F-D0D50E2B3BD1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
28
build.sh
Normal file
28
build.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
outdir="bin"
|
||||
project="SharpCalculator.Avalonia"
|
||||
|
||||
# Somebody broke dotnet10 sdk .target files
|
||||
# To publish self-contained trimmed binary you should add <PublishTrimmed>true</PublishTrimmed> to project file.
|
||||
# Command-line option -p:PublishTrimmed=true produces an error.
|
||||
# Same with <PublishAot>true</PublishAot> if you want AOT compilation.
|
||||
args="
|
||||
--self-contained
|
||||
--use-current-runtime
|
||||
-p:PublishSingleFile=true
|
||||
-p:TrimMode=partial
|
||||
-p:EnableCompressionInSingleFile=true
|
||||
-p:OptimizationPreference=Size
|
||||
-p:InvariantGlobalization=true
|
||||
-p:DebugType=none
|
||||
-p:IncludeNativeLibrariesForSelfExtract=true"
|
||||
|
||||
rm -rf "$outdir"
|
||||
command="dotnet publish $project -c Release -o $outdir $args"
|
||||
echo "$command"
|
||||
$command
|
||||
|
||||
find "$outdir" -name '*.pdb' -delete -printf "deleted '%p'\n"
|
||||
tree -sh "$outdir"
|
||||
BIN
screenshot.jpg
Normal file
BIN
screenshot.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
uml/FusionCalculator.png
Normal file
BIN
uml/FusionCalculator.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 596 KiB |
3256
uml/FusionCalculator.yEd.graphml
Normal file
3256
uml/FusionCalculator.yEd.graphml
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user