Kotlin - Phone Number Complete
This commit is contained in:
parent
7bc0e81574
commit
571d943aa6
58 changed files with 2784 additions and 6 deletions
15
kotlin/leap/.idea/workspace.xml
generated
15
kotlin/leap/.idea/workspace.xml
generated
|
@ -35,8 +35,8 @@
|
|||
<file leaf-file-name="LeapTest.kt" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/test/kotlin/LeapTest.kt">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="266">
|
||||
<caret line="17" column="5" lean-forward="true" selection-start-line="17" selection-start-column="5" selection-end-line="17" selection-end-column="5" />
|
||||
<state relative-caret-position="304">
|
||||
<caret line="19" column="4" lean-forward="true" selection-start-line="19" selection-start-column="4" selection-end-line="19" selection-end-column="4" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
|
@ -484,7 +484,7 @@
|
|||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/../anagram" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/../robot-name" />
|
||||
</component>
|
||||
<component name="PsiViewer.ProjectComponent">
|
||||
<option name="HIGHLIGHT" value="false" />
|
||||
|
@ -918,6 +918,9 @@
|
|||
<servers />
|
||||
</component>
|
||||
<component name="TestHistory">
|
||||
<history-entry file="LeapTest - 2017.06.05 at 09h 46m 34s.xml">
|
||||
<configuration name="LeapTest" configurationId="JUnit" />
|
||||
</history-entry>
|
||||
<history-entry file="LeapTest_leapYear - 2017.06.05 at 09h 46m 19s.xml">
|
||||
<configuration name="LeapTest.leapYear" configurationId="JUnit" />
|
||||
</history-entry>
|
||||
|
@ -945,7 +948,7 @@
|
|||
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="PsiViewer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32896176" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32896176" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
|
@ -993,8 +996,8 @@
|
|||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/test/kotlin/LeapTest.kt">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="266">
|
||||
<caret line="17" column="5" lean-forward="true" selection-start-line="17" selection-start-column="5" selection-end-line="17" selection-end-column="5" />
|
||||
<state relative-caret-position="304">
|
||||
<caret line="19" column="4" lean-forward="true" selection-start-line="19" selection-start-column="4" selection-end-line="19" selection-end-column="4" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
|
|
BIN
kotlin/phone-number/.gradle/3.5/file-changes/last-build.bin
Normal file
BIN
kotlin/phone-number/.gradle/3.5/file-changes/last-build.bin
Normal file
Binary file not shown.
BIN
kotlin/phone-number/.gradle/3.5/taskHistory/taskHistory.lock
Normal file
BIN
kotlin/phone-number/.gradle/3.5/taskHistory/taskHistory.lock
Normal file
Binary file not shown.
0
kotlin/phone-number/.gradle/buildOutputCleanup/built.bin
Normal file
0
kotlin/phone-number/.gradle/buildOutputCleanup/built.bin
Normal file
|
@ -0,0 +1,2 @@
|
|||
#Mon Jun 05 10:10:12 EDT 2017
|
||||
gradle.version=3.5
|
|
@ -0,0 +1 @@
|
|||
|
9
kotlin/phone-number/.idea/compiler.xml
generated
Normal file
9
kotlin/phone-number/.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel>
|
||||
<module name="phone-number_main" target="1.8" />
|
||||
<module name="phone-number_test" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
19
kotlin/phone-number/.idea/gradle.xml
generated
Normal file
19
kotlin/phone-number/.idea/gradle.xml
generated
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="C:/Gradle/gradle-3.5" />
|
||||
<option name="gradleJvm" value="#JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="useAutoImport" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
11
kotlin/phone-number/.idea/libraries/Gradle__junit_junit_4_12.xml
generated
Normal file
11
kotlin/phone-number/.idea/libraries/Gradle__junit_junit_4_12.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: junit:junit:4.12">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa/junit-4.12-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/phone-number/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
generated
Normal file
11
kotlin/phone-number/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.hamcrest:hamcrest-core:1.3">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml
generated
Normal file
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains:annotations:13.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/5991ca87ef1fb5544943d9abc5a9a37583fabe03/annotations-13.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml
generated
Normal file
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.1.1/98e484e67f913e934559f7f55f0c94be5593f03c/kotlin-stdlib-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.1.1/a287944d92875a1f3c2161e5cddaede7720913d1/kotlin-stdlib-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml
generated
Normal file
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains.kotlin:kotlin-test:1.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test/1.1.1/5a852a554eb4f9fb93efdffa352b7983ed595e32/kotlin-test-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test/1.1.1/4b9a869f86569edea4a07d19b9749ac835fb7207/kotlin-test-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml
generated
Normal file
11
kotlin/phone-number/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit/1.1.1/a1865f59b6f72597452e5bdfefeb14d13bc31c7d/kotlin-test-junit-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit/1.1.1/ed59de63c4565c708124caaa4e86562a780f9ba0/kotlin-test-junit-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
22
kotlin/phone-number/.idea/misc.xml
generated
Normal file
22
kotlin/phone-number/.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="Java 1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ProjectJDKs.UI">
|
||||
<settings>
|
||||
<last-edited>1.8</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
10
kotlin/phone-number/.idea/modules.xml
generated
Normal file
10
kotlin/phone-number/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/phone-number.iml" filepath="$PROJECT_DIR$/phone-number.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/phone-number_main.iml" filepath="$PROJECT_DIR$/.idea/modules/phone-number_main.iml" group="phone-number" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/phone-number_test.iml" filepath="$PROJECT_DIR$/.idea/modules/phone-number_test.iml" group="phone-number" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
40
kotlin/phone-number/.idea/modules/phone-number_main.iml
generated
Normal file
40
kotlin/phone-number/.idea/modules/phone-number_main.iml
generated
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="phone-number:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="kotlin-language" name="Kotlin">
|
||||
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
|
||||
<compilerSettings />
|
||||
<compilerArguments>
|
||||
<option name="noStdlib" value="true" />
|
||||
<option name="noReflect" value="true" />
|
||||
<option name="moduleName" value="phone-number_main" />
|
||||
<option name="jvmTarget" value="1.6" />
|
||||
<option name="addCompilerBuiltIns" value="true" />
|
||||
<option name="loadBuiltInsFromDependencies" value="true" />
|
||||
<option name="languageVersion" value="1.1" />
|
||||
<option name="apiVersion" value="1.1" />
|
||||
<option name="pluginClasspaths">
|
||||
<array />
|
||||
</option>
|
||||
<option name="coroutinesWarn" value="true" />
|
||||
<option name="pluginOptions">
|
||||
<array />
|
||||
</option>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/../../build/classes/main" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../src/main">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
|
||||
</component>
|
||||
</module>
|
46
kotlin/phone-number/.idea/modules/phone-number_test.iml
generated
Normal file
46
kotlin/phone-number/.idea/modules/phone-number_test.iml
generated
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="phone-number:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="kotlin-language" name="Kotlin">
|
||||
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
|
||||
<compilerSettings />
|
||||
<compilerArguments>
|
||||
<option name="noStdlib" value="true" />
|
||||
<option name="noReflect" value="true" />
|
||||
<option name="moduleName" value="phone-number_main" />
|
||||
<option name="jvmTarget" value="1.6" />
|
||||
<option name="addCompilerBuiltIns" value="true" />
|
||||
<option name="loadBuiltInsFromDependencies" value="true" />
|
||||
<option name="languageVersion" value="1.1" />
|
||||
<option name="apiVersion" value="1.1" />
|
||||
<option name="pluginClasspaths">
|
||||
<array />
|
||||
</option>
|
||||
<option name="coroutinesWarn" value="true" />
|
||||
<option name="pluginOptions">
|
||||
<array />
|
||||
</option>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output-test url="file://$MODULE_DIR$/../../build/classes/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../src/test">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/kotlin" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="phone-number_main" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test:1.1.1" level="project" />
|
||||
</component>
|
||||
<component name="TestModuleProperties" production-module="phone-number_main" />
|
||||
</module>
|
1027
kotlin/phone-number/.idea/workspace.xml
generated
Normal file
1027
kotlin/phone-number/.idea/workspace.xml
generated
Normal file
File diff suppressed because it is too large
Load diff
34
kotlin/phone-number/README.md
Normal file
34
kotlin/phone-number/README.md
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Phone Number
|
||||
|
||||
Clean up user-entered phone numbers so that they can be sent SMS messages.
|
||||
|
||||
The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda. All NANP-countries share the same international country code `1`.
|
||||
|
||||
NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as *area code*, followed by a seven-digit local number. The first three digits of the local number represent the *exchange code*, followed by the unique four-digit number which is the *subscriber number*.
|
||||
|
||||
|
||||
The format is usually represented as
|
||||
```
|
||||
(NXX)-NXX-XXXX
|
||||
```
|
||||
where N is any digit from 2 through 9 and X is any digit from 0 through 9.
|
||||
|
||||
Your task is to clean up differently formated telephone numbers by removing punctuation and the country code (1) if present.
|
||||
|
||||
**Example:**
|
||||
+1 (613)-995-0253
|
||||
613-995-0253
|
||||
1 613 995 0253
|
||||
613.995.0253
|
||||
- - - - - - - - - - - - -
|
||||
6139950253
|
||||
|
||||
**Note:** As this exercise only deals with telephone numbers used in NANP-countries only 1 is considered a valid country code.
|
||||
|
||||
## Source
|
||||
|
||||
Event Manager by JumpstartLab [http://tutorials.jumpstartlab.com/projects/eventmanager.html](http://tutorials.jumpstartlab.com/projects/eventmanager.html)
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||
|
28
kotlin/phone-number/build.gradle
Normal file
28
kotlin/phone-number/build.gradle
Normal file
|
@ -0,0 +1,28 @@
|
|||
buildscript {
|
||||
ext.kotlin_version = '1.1.1'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
||||
}
|
||||
test {
|
||||
testLogging {
|
||||
exceptionFormat = 'full'
|
||||
events = ["passed", "failed", "skipped"]
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
BIN
kotlin/phone-number/build/classes/main/PhoneNumber.class
Normal file
BIN
kotlin/phone-number/build/classes/main/PhoneNumber.class
Normal file
Binary file not shown.
BIN
kotlin/phone-number/build/classes/test/PhoneNumberTest.class
Normal file
BIN
kotlin/phone-number/build/classes/test/PhoneNumberTest.class
Normal file
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
11001
|
12
kotlin/phone-number/phone-number.iml
Normal file
12
kotlin/phone-number/phone-number.iml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="phone-number" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
0
kotlin/phone-number/src/main/kotlin/.keep
Normal file
0
kotlin/phone-number/src/main/kotlin/.keep
Normal file
20
kotlin/phone-number/src/main/kotlin/PhoneNumber.kt
Normal file
20
kotlin/phone-number/src/main/kotlin/PhoneNumber.kt
Normal file
|
@ -0,0 +1,20 @@
|
|||
class PhoneNumber(inpNumber: String) {
|
||||
init {
|
||||
if (inpNumber.length < 10) throw IllegalArgumentException()
|
||||
if ((inpNumber.length == 11) && !(inpNumber[0] == '1')) throw IllegalArgumentException()
|
||||
}
|
||||
private val digits: String = inpNumber.filter { it.isDigit() }
|
||||
val areaCode: String by lazy {
|
||||
number.substring(0..2)
|
||||
}
|
||||
val number: String by lazy {
|
||||
if (digits.length == 10) {
|
||||
digits.filter { it.isDigit() }.drop(0)
|
||||
}
|
||||
else digits.filter { it.isDigit() }.drop(0).drop(1)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "(" + number.subSequence(0..2) + ") " + number.subSequence(3..5)+ "-" + number.subSequence(6..9)
|
||||
}
|
||||
}
|
78
kotlin/phone-number/src/test/kotlin/PhoneNumberTest.kt
Normal file
78
kotlin/phone-number/src/test/kotlin/PhoneNumberTest.kt
Normal file
|
@ -0,0 +1,78 @@
|
|||
import org.junit.Test
|
||||
import org.junit.Ignore
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.fail
|
||||
|
||||
class PhoneNumberTest {
|
||||
|
||||
|
||||
@Test
|
||||
fun cleansNumber() {
|
||||
val expectedNumber = "1234567890"
|
||||
val actualNumber = PhoneNumber("(123) 456-7890").number
|
||||
|
||||
assertEquals(expectedNumber, actualNumber)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun cleansNumberWithDots() {
|
||||
val expectedNumber = "1234567890"
|
||||
val actualNumber = PhoneNumber("123.456.7890").number
|
||||
|
||||
assertEquals(expectedNumber, actualNumber)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun validWhen11DigitsAndFirstIs1() {
|
||||
val expectedNumber = "1234567890"
|
||||
val actualNumber = PhoneNumber("11234567890").number
|
||||
|
||||
assertEquals(expectedNumber, actualNumber)
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun invalidWhenOnly11Digits() {
|
||||
val actualNumber = PhoneNumber("21234567890")
|
||||
|
||||
fail("IllegalArgumentException should have been thrown")
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun invalidWhen9Digits() {
|
||||
val actualNumber = PhoneNumber("123456789")
|
||||
|
||||
fail("IllegalArgumentException should have been thrown")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun areaCode() {
|
||||
val expectedAreaCode = "123"
|
||||
val actualAreaCode = PhoneNumber("1234567890").areaCode
|
||||
|
||||
assertEquals(expectedAreaCode, actualAreaCode)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun toStringPrint() {
|
||||
val expectedtoStringNumber = "(123) 456-7890"
|
||||
val actualtoStringNumber = PhoneNumber("1234567890").toString()
|
||||
|
||||
assertEquals(expectedtoStringNumber, actualtoStringNumber)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun toStringPrintWithFullUSPhoneNumber() {
|
||||
val expectedtoStringNumber = "(123) 456-7890"
|
||||
val actualtoStringNumber = PhoneNumber("11234567890").toString()
|
||||
|
||||
assertEquals(expectedtoStringNumber, actualtoStringNumber)
|
||||
}
|
||||
|
||||
}
|
BIN
kotlin/robot-name/.gradle/3.5/file-changes/last-build.bin
Normal file
BIN
kotlin/robot-name/.gradle/3.5/file-changes/last-build.bin
Normal file
Binary file not shown.
BIN
kotlin/robot-name/.gradle/3.5/taskHistory/taskHistory.lock
Normal file
BIN
kotlin/robot-name/.gradle/3.5/taskHistory/taskHistory.lock
Normal file
Binary file not shown.
0
kotlin/robot-name/.gradle/buildOutputCleanup/built.bin
Normal file
0
kotlin/robot-name/.gradle/buildOutputCleanup/built.bin
Normal file
|
@ -0,0 +1,2 @@
|
|||
#Mon Jun 05 09:48:03 EDT 2017
|
||||
gradle.version=3.5
|
|
@ -0,0 +1 @@
|
|||
|
9
kotlin/robot-name/.idea/compiler.xml
generated
Normal file
9
kotlin/robot-name/.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel>
|
||||
<module name="robot-name_main" target="1.8" />
|
||||
<module name="robot-name_test" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
19
kotlin/robot-name/.idea/gradle.xml
generated
Normal file
19
kotlin/robot-name/.idea/gradle.xml
generated
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="C:/Gradle/gradle-3.5" />
|
||||
<option name="gradleJvm" value="#JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="useAutoImport" value="true" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
11
kotlin/robot-name/.idea/libraries/Gradle__junit_junit_4_12.xml
generated
Normal file
11
kotlin/robot-name/.idea/libraries/Gradle__junit_junit_4_12.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: junit:junit:4.12">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa/junit-4.12-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/robot-name/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
generated
Normal file
11
kotlin/robot-name/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.hamcrest:hamcrest-core:1.3">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml
generated
Normal file
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains:annotations:13.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/5991ca87ef1fb5544943d9abc5a9a37583fabe03/annotations-13.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml
generated
Normal file
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_1_1.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.1.1/98e484e67f913e934559f7f55f0c94be5593f03c/kotlin-stdlib-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.1.1/a287944d92875a1f3c2161e5cddaede7720913d1/kotlin-stdlib-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml
generated
Normal file
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_1_1.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains.kotlin:kotlin-test:1.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test/1.1.1/5a852a554eb4f9fb93efdffa352b7983ed595e32/kotlin-test-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test/1.1.1/4b9a869f86569edea4a07d19b9749ac835fb7207/kotlin-test-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml
generated
Normal file
11
kotlin/robot-name/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_1_1.xml
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.1.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit/1.1.1/a1865f59b6f72597452e5bdfefeb14d13bc31c7d/kotlin-test-junit-1.1.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit/1.1.1/ed59de63c4565c708124caaa4e86562a780f9ba0/kotlin-test-junit-1.1.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
22
kotlin/robot-name/.idea/misc.xml
generated
Normal file
22
kotlin/robot-name/.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="Java 1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/classes" />
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ProjectJDKs.UI">
|
||||
<settings>
|
||||
<last-edited>1.8</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
10
kotlin/robot-name/.idea/modules.xml
generated
Normal file
10
kotlin/robot-name/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/robot-name.iml" filepath="$PROJECT_DIR$/robot-name.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/robot-name_main.iml" filepath="$PROJECT_DIR$/.idea/modules/robot-name_main.iml" group="robot-name" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/robot-name_test.iml" filepath="$PROJECT_DIR$/.idea/modules/robot-name_test.iml" group="robot-name" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
40
kotlin/robot-name/.idea/modules/robot-name_main.iml
generated
Normal file
40
kotlin/robot-name/.idea/modules/robot-name_main.iml
generated
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="robot-name:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="kotlin-language" name="Kotlin">
|
||||
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
|
||||
<compilerSettings />
|
||||
<compilerArguments>
|
||||
<option name="noStdlib" value="true" />
|
||||
<option name="noReflect" value="true" />
|
||||
<option name="moduleName" value="robot-name_main" />
|
||||
<option name="jvmTarget" value="1.6" />
|
||||
<option name="addCompilerBuiltIns" value="true" />
|
||||
<option name="loadBuiltInsFromDependencies" value="true" />
|
||||
<option name="languageVersion" value="1.1" />
|
||||
<option name="apiVersion" value="1.1" />
|
||||
<option name="pluginClasspaths">
|
||||
<array />
|
||||
</option>
|
||||
<option name="coroutinesWarn" value="true" />
|
||||
<option name="pluginOptions">
|
||||
<array />
|
||||
</option>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/../../build/classes/main" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../src/main">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/kotlin" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
|
||||
</component>
|
||||
</module>
|
46
kotlin/robot-name/.idea/modules/robot-name_test.iml
generated
Normal file
46
kotlin/robot-name/.idea/modules/robot-name_test.iml
generated
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="robot-name:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="kotlin-language" name="Kotlin">
|
||||
<configuration version="2" platform="JVM 1.6" useProjectSettings="false">
|
||||
<compilerSettings />
|
||||
<compilerArguments>
|
||||
<option name="noStdlib" value="true" />
|
||||
<option name="noReflect" value="true" />
|
||||
<option name="moduleName" value="robot-name_main" />
|
||||
<option name="jvmTarget" value="1.6" />
|
||||
<option name="addCompilerBuiltIns" value="true" />
|
||||
<option name="loadBuiltInsFromDependencies" value="true" />
|
||||
<option name="languageVersion" value="1.1" />
|
||||
<option name="apiVersion" value="1.1" />
|
||||
<option name="pluginClasspaths">
|
||||
<array />
|
||||
</option>
|
||||
<option name="coroutinesWarn" value="true" />
|
||||
<option name="pluginOptions">
|
||||
<array />
|
||||
</option>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output-test url="file://$MODULE_DIR$/../../build/classes/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../../src/test">
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/kotlin" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="robot-name_main" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test-junit:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-test:1.1.1" level="project" />
|
||||
</component>
|
||||
<component name="TestModuleProperties" production-module="robot-name_main" />
|
||||
</module>
|
1016
kotlin/robot-name/.idea/workspace.xml
generated
Normal file
1016
kotlin/robot-name/.idea/workspace.xml
generated
Normal file
File diff suppressed because it is too large
Load diff
24
kotlin/robot-name/README.md
Normal file
24
kotlin/robot-name/README.md
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Robot Name
|
||||
|
||||
Manage robot factory settings.
|
||||
|
||||
When robots come off the factory floor, they have no name.
|
||||
|
||||
The first time you boot them up, a random name is generated in the format
|
||||
of two uppercase letters followed by three digits, such as RX837 or BC811.
|
||||
|
||||
Every once in a while we need to reset a robot to its factory settings,
|
||||
which means that their name gets wiped. The next time you ask, it will
|
||||
respond with a new random name.
|
||||
|
||||
The names must be random: they should not follow a predictable sequence.
|
||||
Random names means a risk of collisions. Your solution must ensure that
|
||||
every existing robot has a unique name.
|
||||
|
||||
## Source
|
||||
|
||||
A debugging session with Paul Blackwell at gSchool. [http://gschool.it](http://gschool.it)
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||
|
28
kotlin/robot-name/build.gradle
Normal file
28
kotlin/robot-name/build.gradle
Normal file
|
@ -0,0 +1,28 @@
|
|||
buildscript {
|
||||
ext.kotlin_version = '1.1.1'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
||||
}
|
||||
test {
|
||||
testLogging {
|
||||
exceptionFormat = 'full'
|
||||
events = ["passed", "failed", "skipped"]
|
||||
}
|
||||
}
|
BIN
kotlin/robot-name/build/classes/main/Robot.class
Normal file
BIN
kotlin/robot-name/build/classes/main/Robot.class
Normal file
Binary file not shown.
BIN
kotlin/robot-name/build/classes/test/RobotTest$Companion.class
Normal file
BIN
kotlin/robot-name/build/classes/test/RobotTest$Companion.class
Normal file
Binary file not shown.
BIN
kotlin/robot-name/build/classes/test/RobotTest.class
Normal file
BIN
kotlin/robot-name/build/classes/test/RobotTest.class
Normal file
Binary file not shown.
1
kotlin/robot-name/build/kotlin-build/caches/version.txt
Normal file
1
kotlin/robot-name/build/kotlin-build/caches/version.txt
Normal file
|
@ -0,0 +1 @@
|
|||
11001
|
12
kotlin/robot-name/robot-name.iml
Normal file
12
kotlin/robot-name/robot-name.iml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="robot-name" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
0
kotlin/robot-name/src/main/kotlin/.keep
Normal file
0
kotlin/robot-name/src/main/kotlin/.keep
Normal file
28
kotlin/robot-name/src/main/kotlin/Robot.kt
Normal file
28
kotlin/robot-name/src/main/kotlin/Robot.kt
Normal file
|
@ -0,0 +1,28 @@
|
|||
import java.util.Random
|
||||
|
||||
|
||||
class Robot {
|
||||
var name: String = generateName()
|
||||
|
||||
fun reset(){
|
||||
name = generateName()
|
||||
}
|
||||
|
||||
private fun generateName(): String{
|
||||
var nameString: String = ""
|
||||
nameString += generateRandomString(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
nameString += generateRandomString(2, "0123456789")
|
||||
return nameString
|
||||
}
|
||||
|
||||
private fun generateRandomString(length: Int, charList: String): String{
|
||||
var returnString: String = ""
|
||||
val rng: Random = Random()
|
||||
for (i in (0..length)){
|
||||
returnString += charList[rng.nextInt().coerceAtLeast(0).rem(charList.length)]
|
||||
}
|
||||
return returnString
|
||||
}
|
||||
|
||||
|
||||
}
|
36
kotlin/robot-name/src/test/kotlin/RobotTest.kt
Normal file
36
kotlin/robot-name/src/test/kotlin/RobotTest.kt
Normal file
|
@ -0,0 +1,36 @@
|
|||
import org.junit.Test
|
||||
import org.junit.Ignore
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class RobotTest {
|
||||
|
||||
companion object {
|
||||
val EXPECTED_ROBOT_NAME_PATTERN = Regex("[A-Z]{2}\\d{3}")
|
||||
private fun isValidName(name: String) = EXPECTED_ROBOT_NAME_PATTERN.matches(name)
|
||||
}
|
||||
|
||||
val robot = Robot()
|
||||
|
||||
|
||||
@Test
|
||||
fun hasName() {
|
||||
assertTrue(isValidName(robot.name), "Robot name ${robot.name} didn't match expected pattern.")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun differentRobotsHaveDifferentNames() {
|
||||
assertNotEquals(robot.name, Robot().name)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetName() {
|
||||
val name = robot.name
|
||||
robot.reset()
|
||||
|
||||
val name2 = robot.name
|
||||
assertNotEquals(name, name2)
|
||||
assertTrue(isValidName(name2), "Robot name $name2 didn't match expected pattern.")
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue