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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@
Негативная проверка:
* хотя бы один робот использован не по назначению;
* хотя бы один робот заправлен не тем топливом.

----
Для проверяющего:
https://nda.ya.ru/t/E8NjEMZW5CLfza
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ dependencies {

test {
useJUnitPlatform()
}

compileJava.options.encoding = 'UTF-8' // устанавливает кодировку для компилируемого кода
javadoc.options.encoding = 'UTF-8' // устанавливает кодировку для генерируемой документации
compileTestJava.options.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

8 changes: 8 additions & 0 deletions src/main/java/qa/ChiefBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package qa;

public class ChiefBot extends Robot implements AtomicEnergy, FuelEnergy, ElectricEnergy { //наследование
public Boolean haveCookAbility() {
return true;
}

}
20 changes: 20 additions & 0 deletions src/main/java/qa/ElectricEnergy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package qa;

public interface ElectricEnergy {

default void fillElectricity(int amountElectricity) { //инкапсуляция
if (amountElectricity > 20) {
System.out.println("I'm ok");
}

System.out.println("Need refill Electricity");
}

default int refillElectricity(int amountElectricity) { //инкапсуляция
if (amountElectricity < 20) {
return 100;
}

return 0;
}
}
20 changes: 20 additions & 0 deletions src/main/java/qa/FuelEnergy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package qa;

public interface FuelEnergy {

default void fillFuel(int amountFuel) { //инкапсуляция
if (amountFuel>0) {
System.out.println("I'm ok");
}

System.out.println("Need refill Fuel");
}
default int refillFuel(int amountFuel) { //инкапсуляция
if (amountFuel==0) {
return 200;
}

return 0;
}
}

14 changes: 14 additions & 0 deletions src/main/java/qa/Robot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package qa;

public class Robot {
public String go() {
return "I go!";
}
public String goFast() {
return "I go fast!";
}
public String fly() {
return "I fly!";
}
}

12 changes: 12 additions & 0 deletions src/main/java/qa/WarBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package qa;

public class WarBot extends Robot implements AtomicEnergy, FuelEnergy, ElectricEnergy { //наследование
public Boolean haveWeapons() {
return true;
}

public Boolean haveShootAbility() {
return true;
}

}
8 changes: 8 additions & 0 deletions src/main/java/qa/WelderBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package qa;

public class WelderBot extends Robot implements AtomicEnergy, FuelEnergy, ElectricEnergy { //наследование
public Boolean haveWelderAbility() {
return true;
}

}
26 changes: 26 additions & 0 deletions src/main/java/qa/WrongBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package qa;

public class WrongBot extends ChiefBot implements AtomicEnergy, FuelEnergy, ElectricEnergy { //наследование
@Override // полиморфизм
public Boolean haveCookAbility() {
return false;
}

public Boolean haveWelderAbility() {
return true;
}
public void fillFuelWrong(int amountFuel) {
if (amountFuel>0) {
System.out.println("I'm ok");
}

System.out.println("Need refill Fuel");
}
public String refillFuelWrong(int amountFuel) {
if (amountFuel==0) {
return "200 kg coal";
}

return "now enough";
}
}
46 changes: 46 additions & 0 deletions src/test/java/ChiefBotTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import org.junit.jupiter.api.Test;
import qa.AtomicEnergy;
import qa.ElectricEnergy;
import qa.FuelEnergy;
import qa.ChiefBot;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ChiefBotTests {

ChiefBot chiefBot = new ChiefBot();
@Test
public void getWarBotAbilities() throws Exception {
assertEquals("I go!", chiefBot.go());
assertEquals("I go fast!", chiefBot.goFast());
assertEquals("I fly!", chiefBot.fly());
assertEquals(true, chiefBot.haveCookAbility());
}

AtomicEnergy atomicEnergyBot = new ChiefBot();

@Test
public void getAtomicFuel() throws Exception {
atomicEnergyBot.fillReactor(50);
Boolean actual = atomicEnergyBot.refillAtom(50);
assertEquals(true, actual);
}

FuelEnergy fuelEnergyBot = new ChiefBot();

@Test
public void getOilFuel() throws Exception {
fuelEnergyBot.fillFuel(0);
int actual = fuelEnergyBot.refillFuel(0);
assertEquals(200, actual);
}

ElectricEnergy electricEnergyBot = new ChiefBot();

@Test
public void getElectricity() throws Exception {
electricEnergyBot.fillElectricity(19);
int actual = electricEnergyBot.refillElectricity(19);
assertEquals(100, actual);
}

}
14 changes: 12 additions & 2 deletions src/test/java/ReadFileTests.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class ReadFileTests {

@Test
public void secondLineShouldHabAlloha(){
//write here second task
public void secondLineShouldHabAlloha() throws IOException {

String expected_value = "аллоха";

String line2 = Files.readAllLines(Paths.get("src/test/resources/ReadFileTests.txt")).get(1);
assertEquals(expected_value, line2);

}
}
57 changes: 57 additions & 0 deletions src/test/java/WarBotTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import org.junit.jupiter.api.Test;
import qa.AtomicEnergy;
import qa.ElectricEnergy;
import qa.FuelEnergy;
import qa.WarBot;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class WarBotTests {

WarBot warbot = new WarBot();
@Test
public void getWarBotAbilities() throws Exception {
assertEquals("I go!", warbot.go());
assertEquals("I go fast!", warbot.goFast());
assertEquals("I fly!", warbot.fly());
assertEquals(true, warbot.haveShootAbility());
assertEquals(true, warbot.haveWeapons());
}

AtomicEnergy atomicEnergyBot = new WarBot();

@Test
public void getAtomicFuel() throws Exception {
atomicEnergyBot.fillReactor(50);
Boolean actual = atomicEnergyBot.refillAtom(50);
assertEquals(true, actual);
}

FuelEnergy fuelEnergyBot = new WarBot();

@Test
public void getOilFuel() throws Exception {
fuelEnergyBot.fillFuel(0);
int actual = fuelEnergyBot.refillFuel(0);
assertEquals(200, actual);
}

ElectricEnergy electricEnergyBot = new WarBot();

@Test
public void getElectricity() throws Exception {
electricEnergyBot.fillElectricity(19);
int actual = electricEnergyBot.refillElectricity(19);
assertEquals(100, actual);
}


}








47 changes: 47 additions & 0 deletions src/test/java/WelderBotTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import org.junit.jupiter.api.Test;
import qa.AtomicEnergy;
import qa.ElectricEnergy;
import qa.FuelEnergy;
import qa.WelderBot;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class WelderBotTests {

WelderBot welderBot = new WelderBot();

@Test
public void getWelderBotAbilities() throws Exception {
assertEquals("I go!", welderBot.go());
assertEquals("I go fast!", welderBot.goFast());
assertEquals("I fly!", welderBot.fly());
assertEquals(true, welderBot.haveWelderAbility());
}


AtomicEnergy atomicEnergyBot = new WelderBot();

@Test
public void getAtomicFuel() throws Exception {
atomicEnergyBot.fillReactor(50);
Boolean actual = atomicEnergyBot.refillAtom(50);
assertEquals(true, actual);
}

FuelEnergy fuelEnergyBot = new WelderBot();

@Test
public void getOilFuel() throws Exception {
fuelEnergyBot.fillFuel(0);
int actual = fuelEnergyBot.refillFuel(0);
assertEquals(200, actual);
}

ElectricEnergy electricEnergyBot = new WelderBot();

@Test
public void getElectricity() throws Exception {
electricEnergyBot.fillElectricity(19);
int actual = electricEnergyBot.refillElectricity(19);
assertEquals(100, actual);
}
}
18 changes: 7 additions & 11 deletions src/test/java/WithProblemsTests.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class WithProblemsTests {

private final String CONST = "const";
private String CONST = "const";
private final static String bd = "pui";


@Test
public void equalsOneToOne(){
assertEquals("1", "1");
Expand All @@ -24,17 +23,16 @@ public void assignValueToConstVar(){
}

@Test
public static void equalsOneToOne(){
public void equalsOneToOne1(){
assertEquals(1, 1);
}



@Test
public void stringsMustBeEquals(){
String res = "a";

if (bd == new String("pui")) {
if (bd.equals(new String("pui"))) {
res = "asd";
}

Expand All @@ -43,10 +41,8 @@ public void stringsMustBeEquals(){

@Test
public void successfullyRemovingFirstElementFromList(){
List<String> sourceData = List.of("1", "viskas", "chupocabra");
for (String element: sourceData){
sourceData.remove(element);
}
List<String> sourceData = new ArrayList<>(List.of("1", "viskas", "chupocabra"));
sourceData.remove("1");
assertFalse(sourceData.contains("1"));
}

Expand Down
26 changes: 26 additions & 0 deletions src/test/java/WrongBotTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.junit.jupiter.api.Test;
import qa.*;
import static org.junit.jupiter.api.Assertions.assertEquals;


public class WrongBotTests {

WrongBot wrongBot = new WrongBot();

@Test
public void getWrongBotAbilities() throws Exception {
assertEquals("I go!", wrongBot.go());
assertEquals("I go fast!", wrongBot.goFast());
assertEquals("I fly!", wrongBot.fly());
assertEquals(false, wrongBot.haveCookAbility());
assertEquals(true, wrongBot.haveWelderAbility());
}


@Test
public void getOilFuelWrong() throws Exception {
wrongBot.fillFuelWrong(0);
String actual = wrongBot.refillFuelWrong(0);
assertEquals("200", actual, "Wrong Fuel!");
}
}
1 change: 1 addition & 0 deletions src/test/resources/Task3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT COUNT(*)/(SELECT COUNT(*) FROM orders)*100 AS percent FROM orders WHERE promocode_id IS NOT NULL
Loading