-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: 2.1 | ||
orbs: | ||
codecov: codecov/[email protected] | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/golang:1.14.3 | ||
|
||
working_directory: /go/src/github.com/dnozdrin/vowels-coder | ||
steps: | ||
- checkout | ||
- run: | ||
name: "Setup Environment Variables" | ||
command: | | ||
echo "export CODECOV_TOKEN=55930313-e085-47c4-b996-54e2210012c1" >> $BASH_ENV | ||
- run: | ||
name: "Create a temp directory for artifacts" | ||
command: | | ||
mkdir -p /tmp/artifacts | ||
- run: go get -v -t -d ./... | ||
- run: go test -v -coverprofile=coverage.txt -covermode=atomic ./... | ||
- run: go build | ||
- store_artifacts: | ||
path: /tmp/artifacts | ||
|
||
- codecov/upload: | ||
file: coverage.txt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.idea/ | ||
/vowels-coder |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# vowel-coder | ||
<p align="center"> | ||
<img alt="vowels-coder logo" src="assets/logo.svg" height="150"/> | ||
<h3 align="center">vowels-coder</h3> | ||
<p align="center">Vowels encoder / decoder</p> | ||
</p> | ||
|
||
--- | ||
|
||
`vowels-coder` encodes and decodes a given string in English by replacing vowels according to the next map: | ||
|
||
| Letter | Number | | ||
| --- | --- | | ||
| a | 1 | | ||
| e | 2 | | ||
| i | 3 | | ||
| o | 4 | | ||
| u | 5 | | ||
|
||
## Badges | ||
[](https://circleci.com/gh/dnozdrin/vowels-coder) | ||
[](https://codecov.io/gh/dnozdrin/vowels-coder) | ||
[](https://goreportcard.com/report/github.com/dnozdrin/vowels-coder) | ||
[](/LICENSE) | ||
[](https://github.com/dnozdrin/vowels-coder/releases/latest) | ||
|
||
## Installation | ||
- Clone the repository | ||
- In the main directory run `go run build` to build the project | ||
|
||
## Usage | ||
- Run `go run build` to build the project. | ||
- To encode a string, run `./vowels-coder`, enter the text that must be encoded. | ||
- To decode a string, run `./vowels-coder -d`, enter the text that must be decoded. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/dnozdrin/vowels-coder | ||
|
||
go 1.14 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var encoderMap = []string{ | ||
"a", "1", | ||
"e", "2", | ||
"i", "3", | ||
"o", "4", | ||
"u", "5", | ||
} | ||
|
||
var decoderMap = []string{ | ||
"1", "a", | ||
"2", "e", | ||
"3", "i", | ||
"4", "o", | ||
"5", "u", | ||
} | ||
|
||
func main() { | ||
var result string | ||
|
||
decode := flag.Bool("d", false, "Decode.") | ||
flag.Parse() | ||
|
||
fmt.Println("Please enter the text to process:") | ||
s := bufio.NewScanner(os.Stdin) | ||
s.Split(bufio.ScanLines) | ||
if s.Scan() { | ||
if *decode { | ||
result = processText(decoderMap, s.Text()) | ||
} else { | ||
result = processText(encoderMap, s.Text()) | ||
} | ||
|
||
fmt.Println(result) | ||
} | ||
if err := s.Err(); err != nil { | ||
log.Printf("reading input: %s", err) | ||
} | ||
} | ||
|
||
func processText(mapping []string, text string) string { | ||
r := strings.NewReplacer(mapping...) | ||
lowerCase := strings.ToLower(text) | ||
return r.Replace(lowerCase) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
var encodeTests = []struct { | ||
in, out string | ||
}{ | ||
{"aeiou", "12345"}, | ||
{"hello", "h2ll4"}, | ||
{"hi there", "h3 th2r2"}, | ||
{"Hello", "h2ll4"}, | ||
{"HI THERE", "h3 th2r2"}, | ||
} | ||
|
||
func TestEncode(t *testing.T) { | ||
testTextProcessing(t, encodeTests, encoderMap) | ||
} | ||
|
||
func testTextProcessing(t *testing.T, samples []struct{ in, out string }, mapping []string) { | ||
for _, tt := range samples { | ||
t.Run(tt.in, func(t *testing.T) { | ||
s := processText(mapping, tt.in) | ||
if s != tt.out { | ||
t.Errorf("got %q, want %q", s, tt.out) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
var decodeTests = []struct { | ||
in, out string | ||
}{ | ||
{"12345", "aeiou"}, | ||
{"h2ll4", "hello"}, | ||
{"h3 th2r2", "hi there"}, | ||
} | ||
|
||
func TestDecode(t *testing.T) { | ||
testTextProcessing(t, decodeTests, decoderMap) | ||
} |