Skip to content
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

RpG #84

Open
wants to merge 29 commits into
base: Dmitrij_Nazarov
Choose a base branch
from
Open

RpG #84

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
aeb27bc
Sample of 1st lab
Oct 10, 2019
0247220
Tests samples
Oct 17, 2019
d514055
Added actions file
jskonst Oct 24, 2019
b29aa60
Fixed run steps (#28)
jskonst Oct 24, 2019
dbae387
Test actions on PR (#30)
jskonst Oct 24, 2019
953427e
Added tests and sample A|B tasks
jskonst Oct 24, 2019
62b5d9e
Added class task example, added vscode conf
Nov 7, 2019
aa0b4b1
Merge branch 'master' of https://github.com/ISUCT/Tprogramming_147_2019
Nov 7, 2019
dfe9c80
тест гита
Dmitry-ops Dec 12, 2019
0d30c75
тест гита
Dmitry-ops Dec 16, 2019
403c997
Сделал тесты
Dmitry-ops Dec 16, 2019
fea4f80
Тесты
Dmitry-ops Dec 16, 2019
54e0836
Update README.md
Dmitry-ops Dec 16, 2019
c051f7f
Update CourseApp.Tests.csproj
Dmitry-ops Dec 16, 2019
9bfd145
Update CourseApp.csproj
Dmitry-ops Dec 16, 2019
cd1d6ac
Update dotnetcore.yml
Dmitry-ops Dec 16, 2019
c7ea2d2
ТЕСТЫ
Dmitry-ops Dec 16, 2019
729eb79
Merge branch 'Dmitrij_Nazarov' of https://github.com/Dmitry-ops/Tprog…
Dmitry-ops Dec 16, 2019
f8c6ec0
Update dotnetcore.yml
Dmitry-ops Dec 17, 2019
d7c02ee
added 2 lab
Dmitry-ops Dec 22, 2019
f5041fd
Merge branch 'Dmitrij_Nazarov' of https://github.com/Dmitry-ops/Tprog…
Dmitry-ops Dec 22, 2019
3f3f8ea
ya sdelal'
Dmitry-ops Jan 4, 2020
6df2620
ya sdelal'(1)
Dmitry-ops Jan 4, 2020
caf57b0
polymorthism and age
Dmitry-ops Jan 6, 2020
5edbc3a
1
Dmitry-ops Jan 6, 2020
ee56772
RpG
Dmitry-ops Jan 9, 2020
046fa82
RpG v2
Dmitry-ops Jan 9, 2020
b169fb6
delete
Dmitry-ops Jan 9, 2020
b06ea6a
RpG v3
Dmitry-ops Jan 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: .NET Core

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.802
- name: Build with dotnet
run: |
cd CourseApp
dotnet build --configuration Release
- name: Run tests
run: |
cd CourseApp.Tests
dotnet test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ $RECYCLE.BIN/
**/node_modules/*

# Added by Jskonst
.vscode/
Properties/

#####
Expand Down
55 changes: 55 additions & 0 deletions CourseApp.Tests/AgeCounterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using Xunit;

namespace CourseApp.Tests
{
public class AgeCounterTest
{
[Fact]
public void CorrectAgeInputTest()
{
var yeah = new AgeCounter();
Assert.Equal($"Возраст:21 лет, 0 месяцев, 2 дней", yeah.CountAge(12, 10, 1999, 13, 10, 2020));
}

[Fact]
public void FutureDateInputTest()
{
var time = new AgeCounter();
try
{
Assert.Equal($"Возраст:-2 лет, 2 месяцев, 6 дней", time.CountAge(16, 6, 2021, 19, 12, 2019));
}
catch
{
Assert.True(true);
}
}

[Fact]
public void CurrentDayIsBirthdayTest()
{
var time = new AgeCounter();
var day = DateTime.Today.Day;
var month = DateTime.Today.Month;
var year = DateTime.Today.Year;
try
{
Assert.Equal($"Возраст:0 лет, 0 месяцев, 0 дней", time.CountAge(5, 1, 2020, 5, 1, 2020));
}
catch
{
Assert.True(true);
}
}

[Theory]
[InlineData(30, 11, 2000, 19, 0, 19)]
[InlineData(16, 11, 2000, 2, 1, 19)]
public void CurrectYearCountTest(int d, int m, int y, int expD, int expM, int expY)
{
var time = new AgeCounter();
Assert.Equal($"Возраст:{expY} лет, {expM} месяцев, {expD} дней", time.CountAge(d, m, y, 19, 12, 2019));
}
}
}
36 changes: 36 additions & 0 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
using System;
using System.Collections.Generic;
using Xunit;

namespace CourseApp.Tests
{
public class DemoTest
{
[Theory]
[InlineData(0.2, 45.024015896718936)]
[InlineData(0.3, 18.87433958817845)]
public void TestMyFunction(double x, double exp)
{
Assert.Equal(Program.MyFunction(x), exp, 3);
}

[Fact]

public void TestTaskA()
{
double xn = 0.26;
double xk = 0.66;
double dx = 0.08;
List<double> res = Program.TaskA(xn, xk, dx);
List<double> expy = new List<double> { 26.84410487237168, 13.21117766406966, 6.447227535266805, 3.220397731030495, 1.7472761588502188, 1.1298385487203866 };
for (int i = 0; i < 6; i++)
{
Assert.Equal(expy[i], res[i], 3);
}
}

[Fact]
public void Test1()
{
Assert.True(true);
}

[Fact]
public void TestTaskB()
{
List<double> xB = new List<double> { 0.1, 0.35, 0.4, 0.55, 0.6 };
List<double> taskB = Program.TaskB(xB);
List<double> expy = new List<double> { 102.99803805648071, 12.078220437571703, 7.709481911813682, 2.16507891445927, 1.5347282613199904 };
for (int i = 0; i < 5; i++)
{
Assert.Equal(expy[i], taskB[i], 3);
}
}
}
}
63 changes: 63 additions & 0 deletions CourseApp.Tests/HeroTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Xunit;

namespace CourseApp.Tests
{
public class HeroTest
{
[Fact]
public void TestEmptyConstructor()
{
var item = new Hero();
Assert.Equal(0, item.Level);
Assert.Equal("No role", item.Role);
Assert.True(item.Attack);
}

[Fact]
public void TestSetAge()
{
var item = new Hero();
item.Level = 5;
Assert.Equal(5, item.Level);
}

[Fact]
public void TestShoot()
{
var item = new Hero("Sniper", 10, true);
var act = item.Shoot(true);
Assert.Equal($"Hero Sniper and 10 made the shot!", act);
}

[Fact]
public void TestNumShoot()
{
var item = new Hero("Sniper", 10, true);
var act = item.NumShoot(15);
Assert.Equal($"Sniper made of 15 shots!", act);
}

[Fact]
public void TestCorrectIncorrectSetLevel()
{
var item = new Hero();
try
{
item.Level = -5;
Assert.Equal(-5, item.Level);
}
catch (System.Exception)
{
Assert.True(true);
}
}

[Fact]
public void TestCorrectArray()
{
var characters = new Character[] { new Hero(), new Enemy() };
Assert.Equal(characters[1].ToString(), $"Enemy-No role, 0, True");
}
}
}
23 changes: 23 additions & 0 deletions CourseApp.Tests/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: .NET Core

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.802
- name: Build with dotnet
run: |
cd CourseApp
dotnet build --configuration Release
- name: Run tests
run: |
cd CourseApp.Tests
dotnet test
Binary file added CourseApp/.vscode/CourseApp - Ярлык.lnk
Binary file not shown.
25 changes: 25 additions & 0 deletions CourseApp/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/CourseApp.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions CourseApp/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CourseApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/CourseApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/CourseApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
51 changes: 51 additions & 0 deletions CourseApp/AgeCounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;

namespace CourseApp
{
public class AgeCounter
{
private DateTime now = DateTime.Today;

public string CountAge(int day, int month, int year)
{
var birthday = new DateTime(year, month, day);
var today = DateTime.Today;

if (birthday.Ticks > now.Ticks)
{
throw new Exception("плохая дата;)");
}
else if (birthday.Ticks == now.Ticks)
{
throw new Exception("нельзя вводить текущую дату");
}
else
{
var age = new DateTime(today.Ticks - birthday.Ticks);

return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней";
}
}

public string CountAge(int day, int month, int year, int nowDay, int nowMonth, int nowYear)
{
var birthday = new DateTime(year, month, day);
var today = new DateTime(nowYear, nowMonth, nowDay);

if (birthday.Ticks > now.Ticks)
{
throw new Exception("плохая дата;)");
}
else if (birthday.Ticks == now.Ticks)
{
throw new Exception("нельзя вводить текущую дату");
}
else
{
var age = new DateTime(today.Ticks - birthday.Ticks);

return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней";
}
}
}
}
Loading