Last active
May 20, 2023 16:35
-
-
Save oshikiri/7165e401191b1e52308b29cf220f6d6c to your computer and use it in GitHub Desktop.
puzzle-seq-nil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
object Hello { | |
def main(_args: Array[String]): Unit = { | |
check("1") | |
check("1,2") | |
} | |
def check(s: String) = { | |
val integers = s.split(",") | |
val res1 = lengthIsEqualToOne_1(integers) | |
val res2 = lengthIsEqualToOne_2(integers) | |
println(s"${s} res1=$res1, res2=$res2") | |
} | |
def lengthIsEqualToOne_1(l: Seq[String]): Boolean = { | |
l match { | |
case head :: Nil => true | |
case any => false | |
} | |
} | |
def lengthIsEqualToOne_2(l: Seq[String]): Boolean = { | |
l.length == 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import org.scalatest.funsuite._ | |
class HelloSpec extends AnyFunSuite { | |
test("Seq() lengthIsEqualToOne_1 == false") { | |
assert(!Hello.lengthIsEqualToOne_1(Seq())) | |
} | |
test("Seq(1) lengthIsEqualToOne_1 == true") { | |
assert(Hello.lengthIsEqualToOne_1(Seq("1"))) | |
} | |
test("Seq(1, 2) lengthIsEqualToOne_1 == false") { | |
assert(!Hello.lengthIsEqualToOne_1(Seq("1", "2"))) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
テストは通るが、`1 res1=true` にならない | |
``` | |
sbt:Hello> test | |
[info] Done compiling. | |
[info] HelloSpec: | |
[info] - Seq() lengthIsEqualToOne_1 == false | |
[info] - Seq(1) lengthIsEqualToOne_1 == true | |
[info] - Seq(1, 2) lengthIsEqualToOne_1 == false | |
[info] Run completed in 243 milliseconds. | |
[info] Total number of tests run: 3 | |
[info] Suites: completed 1, aborted 0 | |
[info] Tests: succeeded 3, failed 0, canceled 0, ignored 0, pending 0 | |
[info] All tests passed. | |
[success] Total time: 2 s, completed 2023/05/21 1:26:23 | |
sbt:Hello> run | |
[info] Running example.Hello | |
1 res1=false, res2=true | |
1,2 res1=false, res2=false | |
[success] Total time: 0 s, completed 2023/05/21 1:26:25 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment