Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,15 @@
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
89 changes: 89 additions & 0 deletions src/main/java/HomeTusk/Tests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package HomeTusk;

import org.junit.jupiter.api.Test;
import ru.odnoklassniki.ClassToBeTested;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Created by Dmitry Kachalin
*
* Исходный метод generateIntSequence получает на вход 2 числа типа int:
* startingNumber - начальное число, от которого будет вестись отсчет.
* itemsCount - число раз, которое метож будет последовательно прибавлять к исходному числу 1 и записывать получаемые числа в массив.
*
* Чек-лист:
* 1) Проверка случая, когда itemsCount<0
* 2) Проверка случая, когда itemsCount=0
* 3) Проверка случая, когда startingNumber + itemsCount больше масимального значения типа int
* 4) Проверка случая, когда startingNumber + itemsCount равно масимальному начению типа int
* 5) Проверка случая, когда startingNumber + itemsCount меньше максимального значения типа int
*/


public class Tests{
/**
* 1) Проверка случая, когда itemsCount<0
*/
@Test
public void TestIfItemsCountLessThanZero() {
try{
ClassToBeTested.generateIntSequence(500, -5);
fail();
}
catch(IllegalArgumentException ex){
assertEquals("itemsCount must be greater than 0", ex.getMessage());

}
}

/**
* 2) Проверка случая, когда itemsCount=0
*/
@Test
public void TestIfItemsCountEqualsZero() {
try{
ClassToBeTested.generateIntSequence(100,0);
fail();
}
catch(IllegalArgumentException ex){
assertEquals("itemsCount must be greater than 0", ex.getMessage());
}
}

/**
* 3) Проверка случая, когда startingNumber + itemsCount больше масимального значения типа int
*/
@Test
public void TestIfFinishNumberGreaterThanMaxInt(){
try{
ClassToBeTested.generateIntSequence(Integer.MAX_VALUE - 1, 15);
fail();
}
catch(IllegalArgumentException ex){
assertEquals("can't generate an int greater than integer's max value", ex.getMessage());
}
}

/**
* 4) Проверка случая, когда startingNumber + itemsCount равно масимальному начению типа int
*/
@Test
public void TestIfFinishNumberEqualsManInt(){
int startingNumber = Integer.MAX_VALUE - 2;
int itemsCount = 2;
ClassToBeTested.generateIntSequence( startingNumber, itemsCount);
assertEquals(startingNumber + itemsCount,Integer.MAX_VALUE);
Copy link
Owner

Choose a reason for hiding this comment

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

Очень странная проверка, которая никак не связана с функциональностью тестируемого метода.
Надо проверить результат, который отдал тестовый метод. Но кейс, опять-таки, хороший

}

/**
* 5) Проверка случая, когда startingNumber + itemsCount меньше максимального значения типа int
*/
@Test
public void TestIfEverythingIsNormal(){
int startingNumber = 100;
int itemsCount = 300;
ClassToBeTested.generateIntSequence(startingNumber, itemsCount);
Copy link
Owner

Choose a reason for hiding this comment

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

Тест без проверок - плохой тест. Но кейс нормальный. Надо добавить assert'ы

}
}
Empty file.
Binary file added target/classes/HomeTusk/Tests.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions techno-atom-sample-1.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-all:1.3" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.2.0" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.2.0" level="project" />
</component>
</module>