-
Notifications
You must be signed in to change notification settings - Fork 24
Hamraev_Ivan_Dilshodovich #11
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
base: Hamraev_Ivan_Dilshodovich
Are you sure you want to change the base?
Changes from 1 commit
44a7ac5
89bb0b4
1c8851f
6eba2a3
2fcd3de
735c369
34fdb73
340763b
c703476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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(); | ||
|
|
||
| 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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. необходимы тесты на конструктор |
||
| } | ||
| } | ||
| } | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А вам точно нужно такое число параметров при инициализации?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Для работы методов не обязательно, могу уменьшить, не вопрос
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно завести еще конструктор с меньшим числом параметров |
||
| : base(numberWings) | ||
| { | ||
| this.power = power; | ||
| this.length = length; | ||
| this.weight = weight; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не характерны ли эти свойства для всех самолетов в целом? эти поля стоит унести в базовый класс
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В этом классе стоит оставить только те поля - которые характерны только для гидросамолетов |
||
| this.landingSpeed = landingSpeed; | ||
| this.takeoffSpeed = takeoffSpeed; | ||
| this.lengthFloat = lengthFloat; | ||
| this.numberWings = numberWings; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вот это можно реализовать через вызов родительского конструктора
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Но я не могу получить доступ к переменным родительского конструктора, так как он у меня абстрактный, и переменные соответственно приватные, голову сломал ещё когда писал, как их передавать, в итоге решил в дочерний класс всё запихнуть, а в абстрактном только методы
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. стоп - конструктор то у вас есть у родительского с такими параметрами? |
||
| this.model = model; | ||
| this.maxSpeed = maxSpeed; | ||
| direction = string.Empty; | ||
| speed = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это не обязательно - оно и так будет выставлено в значение по умолчанию
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не очень хорошая практика использовать \n - поскольку это сильно зависит от ОС
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, хотел их изначально использовать, но потом в сторону \n склонился, всё поправлю |
||
|
|
||
| public override void Movement() => Console.WriteLine($"Самолёт движется со скоростью {speed} км/ч, в направлении: {direction}"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Протестировать метод - который просто выводит в консоль будет сложно - проще - возвращать значение (пусть даже и строковое)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот так не надо делать - просто передайте параметры извне
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Решил тоже свойством оформить и поколдовать с Movement) |
||
| } | ||
|
|
||
| public int SpeedUp() => speed == 0 ? speed = takeoffSpeed : speed = maxSpeed; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace CourseApp.Class | ||
| { | ||
| public interface ILanding | ||
| { | ||
| void SpeedDown(); | ||
|
|
||
| void Braking(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace CourseApp.Class | ||
| { | ||
| public interface ITakeoff | ||
| { | ||
| void SetDirection(); | ||
|
|
||
| int SpeedUp(); | ||
| } | ||
| } |
| 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(); | ||
| } | ||
| } |
| 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(); | ||
| } | ||
| } | ||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а зачем 2 раза,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тесты необходимо добавить для всех методов - ну как минимум для getInfo точно