testing
This commit is contained in:
		@ -1,7 +1,11 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import "fmt"
 | 
			
		||||
import (
 | 
			
		||||
        "fmt"
 | 
			
		||||
        "c.infdj.com/GO/courses_golang/hello/morestrings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	fmt.Println("Hello, world.")
 | 
			
		||||
        // fmt.Println("Hello, world.")
 | 
			
		||||
        fmt.Println(morestrings.ReverseRunes("!oG ,olleH"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								hello/morestrings/reverse.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								hello/morestrings/reverse.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
// Package morestrings implements additional functions to manipulate UTF-8
 | 
			
		||||
// encoded strings, beyond what is provided in the standard "strings" package.
 | 
			
		||||
package morestrings
 | 
			
		||||
 | 
			
		||||
// ReverseRunes returns its argument string reversed rune-wise left to right.
 | 
			
		||||
func ReverseRunes(s string) string {
 | 
			
		||||
	r := []rune(s)
 | 
			
		||||
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
 | 
			
		||||
		r[i], r[j] = r[j], r[i]
 | 
			
		||||
	}
 | 
			
		||||
	return string(r)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								hello/morestrings/reverse_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								hello/morestrings/reverse_test.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
package morestrings
 | 
			
		||||
 | 
			
		||||
import "testing"
 | 
			
		||||
 | 
			
		||||
func TestReverseRunes(t *testing.T) {
 | 
			
		||||
	cases := []struct {
 | 
			
		||||
		in, want string
 | 
			
		||||
	}{
 | 
			
		||||
		{"Hello, world", "dlrow ,olleH"},
 | 
			
		||||
		{"Hello, 世界", "界世 ,olleH"},
 | 
			
		||||
		{"", ""},
 | 
			
		||||
	}
 | 
			
		||||
	for _, c := range cases {
 | 
			
		||||
		got := ReverseRunes(c.in)
 | 
			
		||||
		if got != c.want {
 | 
			
		||||
			t.Errorf("ReverseRunes(%q) == %q, want %q", c.in, got, c.want)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user