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
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ru.odnoklassniki.ClassToBeTestedTests;

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

import java.util.List;


/**
* Created by Soldatov Artem as demotests
*/

public class TestGenerateIntSequence {

@Test
public void testSequenceGeneratedCorrectly() {
final int startNum = 21;
final int numCount = 3;
final List<Integer> sequence = ClassToBeTested.generateIntSequence(startNum, numCount);

Assert.assertNotNull(sequence);
Assert.assertEquals(3, sequence.size());
for (int i : sequence) {
Assert.assertEquals(startNum+i,sequence.get(i).intValue());
}
}

@Test
public void testNullItemsCountExceptionThrown() {
try { ClassToBeTested.generateIntSequence(5, 0);
Assert.fail("Method did not throw exception when second items count was 0");
} catch (IllegalArgumentException e) {
Assert.assertEquals("itemsCount must be greater than 0", e.getMessage());
}

}

@Test
public void testMoreThenIntegerMaxValueSequenceGen() {
for (int i = 0; i <1; i++) {
try { ClassToBeTested.generateIntSequence(i, Integer.MAX_VALUE);
Assert.fail("Method did not throw exception when sum startingNumber and itemsCount more then Integer max value");
} catch (IllegalArgumentException e) {
Assert.assertEquals("can't generate an int greater than integer's max value", e.getMessage());
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ru.odnoklassniki.ClassToBeTestedTests;

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

import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.AllOf.allOf;


/**
* Created by Soldatov Artem as demotests
*/

public class TestSortStringsByLength {

@Test
public void testSortedListContainsCorrectLength() throws Exception{
final String str1 = "string01";
final String str2 = "string0123";
final List<String> sortedStrings = ClassToBeTested.sortStringsByLength(str1, str2);

Assert.assertThat(
"Некорретный размер коллекции",
sortedStrings,
allOf(
notNullValue(),
hasSize(equalTo(2))
)
);
}

@Test
public void testSortedListContainsFirstString() throws Exception{
final String str1 = "string1";
final String str2 = "string11";
final List<String> sortedStrings = ClassToBeTested.sortStringsByLength(str1, str2);

Assert.assertThat(
"Ответ не содержит первую строку",
sortedStrings,
contains(str1)
);
}
}