File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ package warmup1
2
+
3
+ // https://codingbat.com/prob/p123384
4
+
5
+ func frontBack (str string ) string {
6
+ n := len (str )
7
+ if n == 1 {
8
+ return str
9
+ }
10
+ return str [n - 1 :n ] + str [1 :n - 1 ] + str [0 :1 ]
11
+ }
Original file line number Diff line number Diff line change
1
+ package warmup1
2
+
3
+ import (
4
+ "strings"
5
+ "testing"
6
+ )
7
+
8
+ func TestSwap (t * testing.T ) {
9
+ actual := frontBack ("back" )
10
+ expected := "kacb"
11
+ if strings .Compare (expected , actual ) != 0 {
12
+ t .Fatalf ("expected \" %s\" but actual is \" %s\" " , expected , actual )
13
+ }
14
+ }
15
+
16
+ func TestOneChar (t * testing.T ) {
17
+ expected := frontBack ("x" )
18
+ actual := "x"
19
+ if strings .Compare (expected , actual ) != 0 {
20
+ t .Fatalf ("expected \" %s\" but actual is \" %s\" " , expected , actual )
21
+ }
22
+ }
23
+
24
+ func TestOddChars (t * testing.T ) {
25
+ actual := frontBack ("abcde" )
26
+ expected := "ebcda"
27
+ if strings .Compare (expected , actual ) != 0 {
28
+ t .Fatalf ("expected \" %s\" but actual is \" %s\" " , expected , actual )
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments