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
16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__junit_junit_4_12.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_hamcrest_hamcrest_all_1_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

637 changes: 637 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions first.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package ru.odnoklassniki;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by Maksim Egorichev on 4/12/18 at 1:53 AM
*/
public class ClassToBeTested {

private ClassToBeTested() {
}

public static List<String> sortStringsByLength(String string1, String string2) throws Exception {
if (string1 == null || string1.trim().length() == 0) {
throw new IllegalArgumentException("string1 must not be null or empty");
}

if (string2 == null || string2.trim().length() == 0) {
throw new IllegalArgumentException("string2 must not be null or empty");
}

final int str1Len = string1.length();
final int str2Len = string2.length();

if (str1Len == str2Len) {
throw new IllegalStateException("strings must be of different length");
}

if (str1Len > str2Len) {
return Arrays.asList(
string1,
string2
);
}

return Arrays.asList(string2, string1);
}

public static List<Integer> generateIntSequence(int startingNumber, int itemsCount) {
if (itemsCount <= 0) {
throw new IllegalArgumentException("itemsCount must be greater than 0");
}

long finishNumber = new Long(startingNumber) + new Long(itemsCount);

if (finishNumber > Integer.MAX_VALUE) {
throw new IllegalArgumentException("can't generate an int greater than integer's max value");
}

List<Integer> intSequence = new ArrayList<Integer>();
for (int i = startingNumber; i < startingNumber + itemsCount; i++) {
intSequence.add(i);
}

return intSequence;
}
}
public class TestGenerateIntSequence {
@Test
public void testTheStringIsZero() throws Exception {
try {
ClassToBeTested.generateIntSequence(1,0);
Assert.fail("Method did not throw exception when itemsCount was 0");
} catch (IllegalArgumentException e) {
Assert.assertEquals("itemsCount must be greater than 0", e.getMessage());
}
}
@Test
public void testTheStringIsMaxValue() throws Exception {
try {
ClassToBeTested.generateIntSequence(2 147 483 648,10);
Assert.fail("Method did not throw exception when startingNumber was more than Integer.MAX_VALUE");
} catch (IllegalArgumentException e) {
Assert.assertEquals("can't generate an int greater than integer's max value", e.getMessage());
}
}
}

public class TestSortStringsByLength {
@Test
public void testTheFirstStringIsNull() throws Exception {
try {
ClassToBeTested.sortStringsByLength(null, "notEmptyString");
Assert.fail("Method did not throw exception when first string was null");
} catch (IllegalArgumentException e) {
Assert.assertEquals("string1 must not be null or empty", e.getMessage());
}
}
@Test
public void testTheSecondStringIsNull() throws Exception {
try {
ClassToBeTested.sortStringsByLength("notEmptyString",null);
Assert.fail("Method did not throw exception when second string was null");
} catch (IllegalArgumentException e) {
Assert.assertEquals("string2 must not be null or empty", e.getMessage());
}
}
@Test
public void testNotDifferentLength() throws Exception {
try {
ClassToBeTested.sortStringsByLength("notEmptyString","notEmptyString");
Assert.fail("Method did not throw exception when strings aren't different length");
} catch (IllegalArgumentException e) {
Assert.assertEquals("strings must be of different length", e.getMessage());
}
}
}
4 changes: 1 addition & 3 deletions src/main/java/ru/odnoklassniki/ClassToBeTested.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import java.util.Arrays;
import java.util.List;

/**
* Created by Maksim Egorichev on 4/12/18 at 1:53 AM
*/

public class ClassToBeTested {

private ClassToBeTested() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package ru.odnoklassniki.GenerateIntSequence;

import org.junit.Assert;
import org.junit.Test;
import ru.odnoklassniki.ClassToBeTested;

import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;

public class TestGenerateIntSequence {
@Test
public void testTheStringIsZero() throws Exception {
try {
ClassToBeTested.generateIntSequence(1, 0);
Assert.fail("Method did not throw exception when itemsCount was 0");
} catch (IllegalArgumentException e) {
Assert.assertEquals("itemsCount must be greater than 0", e.getMessage());
}
}

@Test
public void testTheStringIsGreaterMaxInteger() throws Exception {
try {
ClassToBeTested.generateIntSequence(2147483647, 10);
Assert.fail("Method did not throw exception when startingNumber was more than Integer.MAX_VALUE");
} catch (IllegalArgumentException e) {
Assert.assertEquals("can't generate an int greater than integer's max value", e.getMessage());
}
}
@Test
public void testSumIsGreaterMaxIntegerFail() {

try {
ClassToBeTested.generateIntSequence(2147483647, 100);Assert.fail();
Copy link
Owner

Choose a reason for hiding this comment

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

Переход на новую строку забыла

}

catch (IllegalArgumentException e) {
Assert.assertEquals("can't generate an int greater than integer's max value", e.getMessage());
}
}
@Test
public void testTheStringIsLessZero() throws Exception {
try {
ClassToBeTested.generateIntSequence(1, -10);
Assert.fail("Method did not throw exception when itemsCount was less 0");
} catch (IllegalArgumentException e) {
Assert.assertEquals("itemsCount must be greater than 0", e.getMessage());
}
}
@Test
public void testCorrectString() throws Exception {
Copy link
Owner

Choose a reason for hiding this comment

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

Названия большинства тестов не отображают суть теста

final List<Integer> Sequence = ClassToBeTested.generateIntSequence(0, 10);
Assert.assertNotNull(Sequence);
Assert.assertFalse(Sequence.isEmpty());


}

@Test
public void testCorrectSequenceCreation() throws Exception{
final List<Integer> Result = ClassToBeTested.generateIntSequence(0, 10);
Assert.assertThat(
"The length of sequence isn't equal to 10",
Result, hasSize(equalTo(10)));
Copy link
Owner

Choose a reason for hiding this comment

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

Вот такой проверки недостаточно. Мало проверить, что количество элементов в результирующем списке верное. Надо еще и само содержание списка проверить. Вдруг там неправильно сгенерированная последовательность

}



}

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.
16 changes: 16 additions & 0 deletions techno-atom-sample-1.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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" />
</component>
</module>