Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions CourseApp.RPGSagaTests/CourseApp.RPGSagaTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions CourseApp.RPGSagaTests/RPGSagaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace CourseApp.RPGSagaTests
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}
49 changes: 49 additions & 0 deletions CourseApp.Tests/AutoMethodsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace CourseApp.Tests
{
using CourseApp.RPGSaga;
using Xunit;

public class AutoMethodsTests
{
[Fact]
public void GetInfo_SetSampleData_ReturnCorrectInfo_Auto()
{
Transport auto = new Auto(4.9, 1.71, 2145, 333, 250, "Audi Q8");
Assert.Equal(
@"Info for Audi Q8
Weight: 2145 kg
Length: 4,9 m
Height: 1,71 m
Power: 333 horsepower
Max Speed: 250 km\h", auto.GetInfo());
}

[Fact]
public void CheckConstructor_SetSampleData_ReturnCorrectInfo_Auto()
{
Transport auto = new Auto();

Assert.Equal(
@"Info for Auto
Weight: 0 kg
Length: 0 m
Height: 0 m
Power: 0 horsepower
Max Speed: 0 km\h", auto.GetInfo());
}

[Fact]
public void Movement_CallMovementMethod_CorrectMove_Auto()
{
Transport auto = new Auto();
Assert.Equal(ActionTypes.Move, auto.Movement());
}

[Fact]
public void ToString_CheckStringPresentation_CorrectPresentationOfInstance()
{
Transport auto = new Auto(4.9, 1.71, 2145, 333, 250, "Audi Q8");
Assert.Equal("Auto Audi Q8", auto.ToString());
}
}
}
13 changes: 0 additions & 13 deletions CourseApp.Tests/DemoTest.cs

This file was deleted.

63 changes: 63 additions & 0 deletions CourseApp.Tests/PlaneMethodsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace CourseApp.Tests
{
using CourseApp.RPGSaga;
using Xunit;

public class PlaneMethodsTests
{
[Fact]
public void GetInfo_SetSampleData_ReturnCorrectInfo()
{
Transport plane = new Plane(9.22, 2.74, 1361, 450, 255, "DHC-2 Beaver");
Assert.Equal(
@"Info for DHC-2 Beaver
Weight: 1361 kg
Length: 9,22 m
Height: 2,74 m
Power: 450 horsepower
Max Speed: 255 km\h", plane.GetInfo());
}

[Fact]
public void CheckConstructor_SetSampleData_ReturnCorrectInfo()
{
Transport plane = new Plane();

Assert.Equal(
@"Info for Plane
Weight: 0 kg
Length: 0 m
Height: 0 m
Power: 0 horsepower
Max Speed: 0 km\h", plane.GetInfo());
}

[Fact]
public void Movement_CallMovementMethod_CorrectMoveInfo()
{
var plane = new Plane();
Assert.Equal(ActionTypes.Move, plane.Movement());
}

[Fact]
public void Landing_CallLandingMethod_CorrectLandingInfo()
{
var plane = new Plane();
Assert.Equal(ActionTypes.LAnding, plane.Landing());
}

[Fact]
public void Takeoff_CallLandingMethod_CorrectTakeoffInfo()
{
var plane = new Plane();
Assert.Equal(ActionTypes.TAkeoff, plane.Takeoff());
}

[Fact]
public void ToString_CheckStringPresentation_CorrectPresentationOfInstance()
{
Transport plane = new Plane(9.22, 2.74, 1361, 450, 255, "DHC-2 Beaver");
Assert.Equal("Plane DHC-2 Beaver", plane.ToString());
}
}
}
33 changes: 33 additions & 0 deletions CourseApp/Class/ActionTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace CourseApp.RPGSaga
{
/// <summary>
/// Types of actions.
/// </summary>
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

Зачем ?

public enum ActionTypes
{
/// <summary>
/// No type.
/// </summary>
Nothing,

/// <summary>
/// Type for movement.
/// </summary>
Move,

/// <summary>
/// Type for takeoff.
/// </summary>
TAkeoff,

/// <summary>
/// Types for landing.
/// </summary>
LAnding,

/// <summary>
/// Types for beep.
/// </summary>
BEep,
}
}
38 changes: 38 additions & 0 deletions CourseApp/Class/Auto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace CourseApp.RPGSaga
{
using System;

public class Auto : Transport
{
private ActionTypes actionType;

public Auto()
: this(0, 0, 0, 0, 0, "Auto")
{
}

public Auto(double length, double height, int weight, int power, int maxSpeed, string model)
: base(length, height, weight, power, maxSpeed, model)
{
}

public override string ToString()
{
return $"Auto {Model}";
}

public override ActionTypes Movement()
{
actionType = ActionTypes.Move;
Console.WriteLine($"{Model} is moving at a speed {Speed}km/h");
return actionType;
}

public ActionTypes Beep()
{
actionType = ActionTypes.BEep;
Console.WriteLine("Beep");
return actionType;
}
}
}
6 changes: 6 additions & 0 deletions CourseApp/Class/ILanding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CourseApp.RPGSaga;

public interface ILanding
{
public ActionTypes Landing();
}
6 changes: 6 additions & 0 deletions CourseApp/Class/ITakeoff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace CourseApp.RPGSaga;

public interface ITakeoff
{
public ActionTypes Takeoff();
}
47 changes: 47 additions & 0 deletions CourseApp/Class/Plane.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace CourseApp.RPGSaga
{
using System;

public class Plane : Transport, ILanding, ITakeoff
{
private ActionTypes actionType;

public Plane()
: this(0, 0, 0, 0, 0, "Plane")
{
}

public Plane(double length, double height, int weight, int power, int maxSpeed, string model)
: base(length, height, weight, power, maxSpeed, model)
{
}

public string Direction { get; set; }

public override string ToString()
{
return $"Plane {Model}";
}

public ActionTypes Takeoff()
{
actionType = ActionTypes.TAkeoff;
Console.WriteLine($"{Model} taking off");
return actionType;
}

public ActionTypes Landing()
{
actionType = ActionTypes.LAnding;
Console.WriteLine($"{Model} going to land");
return actionType;
}

public override ActionTypes Movement()
{
actionType = ActionTypes.Move;
Console.WriteLine($"{Model} is moving at a speed {Speed}km/h in the {Direction}");
return actionType;
}
}
}
77 changes: 77 additions & 0 deletions CourseApp/Class/Transport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace CourseApp
{
using System;
using CourseApp.RPGSaga;

public abstract class Transport
{
private int _speed;

public Transport()
: this(0, 0, 0, 0, 0, "No_name")
{
}

public Transport(double length, double height, int weight, int power, int maxSpeed, string model)
{
Length = length;
Weight = weight;
Power = power;
Height = height;
MaxSpeed = maxSpeed;
Model = model;
}

public string Model { get; set; }

public int Power { get; }

public double Length { get; }

public int Weight { get; }

public double Height { get; }

public int MaxSpeed { get; }

public int Speed
{
get
{
return _speed;
}

set
{
try
{
if (value > MaxSpeed || value < 0)
{
throw new Exception($"speed is too large or too little for {Model}");
}
else
{
_speed = value;
}
}
catch (Exception e)
{
new ArgumentException($"Error: {e.Message}");
Console.WriteLine($"Error: {e.Message}");
}
}
}

public abstract ActionTypes Movement();

public string GetInfo()
{
return @$"Info for {Model}
Weight: {Weight} kg
Length: {Length} m
Height: {Height} m
Power: {Power} horsepower
Max Speed: {MaxSpeed} km\h";
}
}
}
4 changes: 0 additions & 4 deletions CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
Loading