-
Notifications
You must be signed in to change notification settings - Fork 10
DZ1 #7
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: master
Are you sure you want to change the base?
DZ1 #7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| 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()); | ||
| } | ||
| } | ||
| } |
| 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(); | ||
| } | ||
|
|
||
| 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 { | ||
|
Owner
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. Названия большинства тестов не отображают суть теста |
||
| 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))); | ||
|
Owner
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,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> |
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.
Переход на новую строку забыла