-
Notifications
You must be signed in to change notification settings - Fork 0
Решение задачи #1
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: main
Are you sure you want to change the base?
Changes from all commits
2815d52
7a8bb66
8264e77
0cd1faf
83517a4
b989939
c6863c3
5b5367e
e149b54
e8a7aa0
54cad78
c714810
6bebfcb
5ef33fd
7ab3ae7
2585b13
786fb4d
11af72e
20302e2
f29194e
6595456
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,2 @@ | ||
| # Compiled class file | ||
| *.class | ||
|
|
||
| # Log file | ||
| *.log | ||
|
|
||
| # BlueJ files | ||
| *.ctxt | ||
|
|
||
| # Mobile Tools for Java (J2ME) | ||
| .mtj.tmp/ | ||
|
|
||
| # Package Files # | ||
| *.jar | ||
| *.war | ||
| *.nar | ||
| *.ear | ||
| *.zip | ||
| *.tar.gz | ||
| *.rar | ||
|
|
||
| # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
| hs_err_pid* | ||
| /out/ | ||
| .idea |
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <module type="JAVA_MODULE" version="4"> | ||
| <component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
| <exclude-output /> | ||
| <content url="file://$MODULE_DIR$"> | ||
| <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
| </content> | ||
| <orderEntry type="inheritedJdk" /> | ||
| <orderEntry type="sourceFolder" forTests="false" /> | ||
| <orderEntry type="library" name="junit:junit:4.12" level="project" /> | ||
| <orderEntry type="module-library"> | ||
| <library name="JUnit5.4"> | ||
| <CLASSES> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.4.2/junit-jupiter-5.4.2.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.4.2/junit-jupiter-api-5.4.2.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.4.2/junit-platform-commons-1.4.2.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.4.2/junit-jupiter-params-5.4.2.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.4.2/junit-jupiter-engine-5.4.2.jar!/" /> | ||
| <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.4.2/junit-platform-engine-1.4.2.jar!/" /> | ||
| </CLASSES> | ||
| <JAVADOC /> | ||
| <SOURCES /> | ||
| </library> | ||
| </orderEntry> | ||
| </component> | ||
| </module> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| public interface Crypt { | ||
| public String crypt(String strToCrypt); | ||
| public String decrypt(String strToDecrypt); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import java.io.IOException; | ||
|
|
||
| public class Cryptor implements Crypt { | ||
|
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. Это сервис и для него правильно - Cryptor. Только вот он же не просто шифровальщик а с некоторой изюминкой, надо отразить это в названии.
Owner
Author
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. Переименовал на CryptorWithTimeAssessment |
||
|
|
||
| CryptorViaString cryptorViaString; | ||
| CryptorViaStringBuilder cryptorViaStringBuilder; | ||
|
|
||
| public Cryptor(CryptorViaString cryptorViaString, CryptorViaStringBuilder cryptorViaStringBuilder) { | ||
| this.cryptorViaString = cryptorViaString; | ||
|
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. Не вижу чтобы ты его использовал и сравнивал время выполнения. Сейчас ты используешь только второй |
||
| this.cryptorViaStringBuilder = cryptorViaStringBuilder; | ||
|
|
||
| } | ||
|
|
||
| public String crypt(String strToCrypt) { | ||
| long m = System.currentTimeMillis(); | ||
| // String cryptedStringViaString = cryptorViaString.crypt(strToCrypt); | ||
| String cryptedStringViaStringBuilder = cryptorViaStringBuilder.crypt(strToCrypt); | ||
| double timeResult = (double) (System.currentTimeMillis() - m); | ||
| System.out.println("Время выполнения шифрования с ипсользованием StringBuilder: " + timeResult); | ||
|
|
||
| return cryptedStringViaStringBuilder; | ||
| } | ||
|
|
||
| public String decrypt(String strToDecrypt) { | ||
| long t = System.currentTimeMillis(); | ||
| // String cryptedStringViaString = cryptorViaString.decrypt(strToDecrypt); | ||
| String cryptedStringViaStringBuilder = cryptorViaStringBuilder.decrypt(strToDecrypt); | ||
| double timeResult = (double) (System.currentTimeMillis() - t); | ||
| System.out.println("Время выполнения шифрования с ипсользованием StringBuilder: " + timeResult); | ||
|
|
||
| return cryptedStringViaStringBuilder; | ||
|
|
||
| } | ||
|
|
||
|
|
||
robotdorog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
|
|
||
| public class CryptorTest { | ||
| CryptorViaString cryptorViaString = new CryptorViaString(); | ||
| CryptorViaStringBuilder cryptorViaStringBuilder = new CryptorViaStringBuilder(); | ||
| StringBuilder testStringBuilder = new StringBuilder(); | ||
|
|
||
|
|
||
| @Test | ||
| public void cryptBasicTest() { | ||
| String testString = "A2a3b3z3tcz3"; | ||
| String resultString = cryptorViaString.crypt("AAaaabbbzzztczzz"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptBasicTest() { | ||
| String testString = "AAaaabbbzzztczzz"; | ||
| String resultString = cryptorViaString.decrypt("A2a3b3z3tcz3"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptOneCharTest() { | ||
| String testString = "a"; | ||
| String resultString = cryptorViaString.crypt("a"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptOneCharTest() { | ||
| String testString = "a"; | ||
| String resultString = cryptorViaString.decrypt("a"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptEmptyStrTest() { | ||
| String testString = ""; | ||
| String resultString = cryptorViaString.crypt(""); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptEmptyStrTest() { | ||
| String testString = ""; | ||
| String resultString = cryptorViaString.decrypt(""); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptOneRepeatTest() { | ||
| String testString = "a3"; | ||
| String resultString = cryptorViaString.crypt("aaa"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptOneRepeatTest() { | ||
| String testString = "aaa"; | ||
| String resultString = cryptorViaString.decrypt("a3"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptNoRepeatTest() { | ||
| String testString = "abcdef"; | ||
| String resultString = cryptorViaString.crypt("abcdef"); | ||
| Assert.assertEquals(testString, resultString); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptNoRepeatTest() { | ||
| String testString = "abcdef"; | ||
| String resultString = cryptorViaString.decrypt("abcdef"); | ||
| Assert.assertEquals(testString, resultString); | ||
|
|
||
| } | ||
|
|
||
| // CryptorViaStringBuilder | ||
|
|
||
| @Test | ||
| public void cryptBasicV2Test() { | ||
| String testStringBuilder = "A2a3b3z3tcz3"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.crypt("AAaaabbbzzztczzz"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptBasicV2Test() { | ||
| String testStringBuilder = "AAaaabbbzzztczzz"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.decrypt("A2a3b3z3tcz3"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptV2OneCharTest() { | ||
| String testStringBuilder = "a"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.crypt("a"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptV2OneCharTest() { | ||
| String testStringBuilder = "a"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.decrypt("a"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptV2EmptyStrTest() { | ||
| String testStringBuilder = ""; | ||
| String resultSringBuilder = cryptorViaStringBuilder.crypt(""); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptV2EmptyStrTest() { | ||
| String testStringBuilder = ""; | ||
| String resultSringBuilder = cryptorViaStringBuilder.decrypt(""); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptV2OneRepeatTest() { | ||
| String testStringBuilder = "a3"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.crypt("aaa"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptV2OneRepeatTest() { | ||
| String testStringBuilder = "aaa"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.decrypt("a3"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void cryptV2NoRepeatTest() { | ||
| String testStringBuilder = "abcdef"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.crypt("abcdef"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
| @Test | ||
| public void decryptV2NoRepeatTest() { | ||
| String testStringBuilder = "abcdef"; | ||
| String resultSringBuilder = cryptorViaStringBuilder.decrypt("abcdef"); | ||
| Assert.assertEquals(testStringBuilder, resultSringBuilder); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
|
|
||
| public class CryptorViaString implements Crypt { | ||
|
|
||
| @Override | ||
| public String crypt(String strToCrypt) { | ||
robotdorog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| String result = ""; | ||
|
|
||
| if (strToCrypt != null && !strToCrypt.equals("")) { | ||
| int count = 0; | ||
| char currentChar = 0; | ||
|
|
||
| for (int i = 0; i < strToCrypt.length(); i++) { | ||
| if (currentChar == strToCrypt.charAt(i)) { | ||
| count++; | ||
| } else { | ||
| if (currentChar != 0) | ||
| result += currentChar; | ||
|
|
||
| if (count > 1) { | ||
| result += count; | ||
| } | ||
| currentChar = strToCrypt.charAt(i); | ||
| count = 1; | ||
| } | ||
| } | ||
| if (count > 1) { | ||
| result += strToCrypt.charAt(strToCrypt.length() - 1); | ||
| result += count; | ||
| } else | ||
| result += strToCrypt.charAt(strToCrypt.length() - 1); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String decrypt(String strToDecrypt) { | ||
|
|
||
| String result = ""; | ||
| char currentChar = 0; | ||
| int count; | ||
|
|
||
| if (strToDecrypt != null && !strToDecrypt.equals("")) { | ||
|
|
||
| for (int i = 0; i < strToDecrypt.length(); i++) { | ||
| if (Character.isDigit(strToDecrypt.charAt(i))) { | ||
| count = Character.getNumericValue(strToDecrypt.charAt(i)); | ||
| for (int j = 1; j < count; j++) { | ||
| result += currentChar; | ||
| } | ||
| } else { | ||
| currentChar = strToDecrypt.charAt(i); | ||
| if (currentChar != 0) | ||
| result += currentChar; | ||
| } | ||
| } | ||
|
|
||
| if (!Character.isDigit(strToDecrypt.charAt(strToDecrypt.length() - 1)) && | ||
| !(currentChar == (strToDecrypt.charAt(strToDecrypt.length() - 1)))) | ||
| result += currentChar; | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Crypt - глагол если я не ошибаюсь, этот интерфейс у тебя описывает сервис. Поэтому здесь должно быть существительное - Cryptor
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.
Переименовал на Cryptor