Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 0 additions & 13 deletions CourseApp.Tests/DemoTest.cs

This file was deleted.

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

public class HydroplaneMethodsTests
{
[Fact]
public void SpeedUp_SetSampleDate_ReturnsCorrectSpeed()
{
Hydroplane hydroplane = new Hydroplane(450, 9, 1361, 80, 90, 8, 2, "DHC-2 Beaver", 255);
var result = hydroplane.SpeedUp();

Assert.Equal(hydroplane.GetSpeed(), result);
}

[Fact]
public void SpeedUpDouble_SetSampleDate_ReturnCorrectSpeed()
{
var hydroplane = new Hydroplane(450, 9, 1361, 80, 90, 8, 2, "DHC-2 Beaver", 255);
hydroplane.SpeedUp();
var result = hydroplane.SpeedUp();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

а зачем 2 раза,

  • вы можете в рамках первого теста проверить

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Тесты необходимо добавить для всех методов - ну как минимум для getInfo точно


Assert.Equal(hydroplane.GetSpeed(), result);
}

[Fact]
public void SpeedDown_SetSampleDate_ReturnCorrectSpeed()
{
var hydroplane = new Hydroplane(450, 9, 1361, 80, 90, 8, 2, "DHC-2 Beaver", 255);
hydroplane.SpeedUp();
hydroplane.SpeedDown();

Assert.Equal(80, hydroplane.GetSpeed());
}

[Fact]
public void Braking_SetSampleDate_ReturnsCorrectSpeed()
{
var hydroplane = new Hydroplane(450, 9, 1361, 80, 90, 8, 2, "DHC-2 Beaver", 255);
hydroplane.SpeedUp();
hydroplane.Braking();

Assert.Equal(0, hydroplane.GetSpeed());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

необходимы тесты на конструктор

}
}
}
56 changes: 56 additions & 0 deletions CourseApp/Class/Hydroplane.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace CourseApp.Class
{
using System;

public class Hydroplane : Plane, ILanding, ITakeoff
{
private int lengthFloat;
private int speed;
private int power;
private int length;
private int weight;
private int landingSpeed;
private int takeoffSpeed;
private int numberWings;
private string direction;
private string model;
private int maxSpeed;

public Hydroplane(int power, int length, int weight, int landingSpeed, int takeoffSpeed, int lengthFloat, int numberWings, string model, int maxSpeed)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

А вам точно нужно такое число параметров при инициализации?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Для работы методов не обязательно, могу уменьшить, не вопрос

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

можно завести еще конструктор с меньшим числом параметров

: base(numberWings)
{
this.power = power;
this.length = length;
this.weight = weight;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

не характерны ли эти свойства для всех самолетов в целом? эти поля стоит унести в базовый класс

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

В этом классе стоит оставить только те поля - которые характерны только для гидросамолетов

this.landingSpeed = landingSpeed;
this.takeoffSpeed = takeoffSpeed;
this.lengthFloat = lengthFloat;
this.numberWings = numberWings;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

вот это можно реализовать через вызов родительского конструктора

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Но я не могу получить доступ к переменным родительского конструктора, так как он у меня абстрактный, и переменные соответственно приватные, голову сломал ещё когда писал, как их передавать, в итоге решил в дочерний класс всё запихнуть, а в абстрактном только методы

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

стоп - конструктор то у вас есть у родительского с такими параметрами?

this.model = model;
this.maxSpeed = maxSpeed;
direction = string.Empty;
speed = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

это не обязательно - оно и так будет выставлено в значение по умолчанию

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Понял, спасибо

}

public override void GetInfo()
=> Console.WriteLine($"Model: {model} \nPower: {power}horsepower \nLength: {length}m \nWeight: {weight}kg \nLanding speed: {landingSpeed}km/h \nTakeoff speed: {takeoffSpeed}km/h \nMax speed: {maxSpeed}km/h");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

не очень хорошая практика использовать \n - поскольку это сильно зависит от ОС
Посмотрите на многострочные строки в c# (начинаются с @)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Да, хотел их изначально использовать, но потом в сторону \n склонился, всё поправлю


public override void Movement() => Console.WriteLine($"Самолёт движется со скоростью {speed} км/ч, в направлении: {direction}");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Протестировать метод - который просто выводит в консоль будет сложно - проще - возвращать значение (пусть даже и строковое)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Сделаем


public override void TakeSpeed() => Console.WriteLine($"Speed right now: {speed}km/h");

public int GetSpeed() => speed;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Это лучше реализовать через свойства в C#


public void SpeedDown() => speed = landingSpeed;

public void Braking() => speed = 0;

public void SetDirection()
{
Console.Write("Введите направление, курс полёта: ");
direction = Console.ReadLine();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Вот так не надо делать - просто передайте параметры извне
SetDirection(int direction))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Решил тоже свойством оформить и поколдовать с Movement)

}

public int SpeedUp() => speed == 0 ? speed = takeoffSpeed : speed = maxSpeed;
}
}
9 changes: 9 additions & 0 deletions CourseApp/Class/ILanding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CourseApp.Class
{
public interface ILanding
{
void SpeedDown();

void Braking();
}
}
9 changes: 9 additions & 0 deletions CourseApp/Class/ITakeoff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CourseApp.Class
{
public interface ITakeoff
{
void SetDirection();

int SpeedUp();
}
}
22 changes: 22 additions & 0 deletions CourseApp/Class/Plane.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace CourseApp
{
public abstract class Plane
{
private int numberWings;

public Plane()
{
}

public Plane(int numberWings)
{
this.numberWings = numberWings;
}

public abstract void TakeSpeed();

public abstract void Movement();

public abstract void GetInfo();
}
}
22 changes: 22 additions & 0 deletions CourseApp/Class/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace CourseApp.Class
{
public class Program
{
public static void Main()
{
Hydroplane hydroplane = new Hydroplane(450, 9, 1361, 80, 90, 8, 2, "DHC-2 Beaver", 255);

hydroplane.GetInfo();
hydroplane.SetDirection();
hydroplane.TakeSpeed();
hydroplane.SpeedUp();
hydroplane.TakeSpeed();
hydroplane.SpeedUp();
hydroplane.Movement();
hydroplane.SpeedDown();
hydroplane.TakeSpeed();
hydroplane.Braking();
hydroplane.TakeSpeed();
}
}
}
12 changes: 0 additions & 12 deletions CourseApp/Program.cs

This file was deleted.