-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file based variation and use a separate package
- Loading branch information
Showing
5 changed files
with
118 additions
and
58 deletions.
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,5 @@ | ||
{ | ||
"go.autocompleteUnimportedPackages": true, | ||
"go.formatTool": "gofmt", | ||
"go.inferGopath": true | ||
} |
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
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,54 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// FindVowels will check if the character is one of a, e, i, o, u | ||
func FindVowels(s string) int { | ||
result := 0 | ||
for _, v := range s { | ||
if strings.ContainsAny("aeiou", string(v)) { | ||
result++ | ||
} | ||
} | ||
return result | ||
} | ||
|
||
// FindDigits will check only for digits from 0 to 9 | ||
func FindDigits(s string) int { | ||
result := 0 | ||
for _, v := range s { | ||
if strings.ContainsAny("1234567890", string(v)) { | ||
result++ | ||
} | ||
} | ||
return result | ||
} | ||
|
||
// FindSymbols will count common symbols appearing on the number keys | ||
func FindSymbols(s string) int { | ||
result := 0 | ||
for _, v := range s { | ||
if strings.ContainsAny("!@€£#$%^&*()", string(v)) { | ||
result++ | ||
} | ||
} | ||
return result | ||
} | ||
|
||
// FindWords will count the number of words without surrounding spaces | ||
func FindWords(s string) int { | ||
return len(strings.Fields(s)) | ||
} | ||
|
||
// PrintReport will display a summary of results | ||
func PrintReport(vowels, digits, symbols, words int) { | ||
fmt.Println("Analysis Summary") | ||
fmt.Println("-------- -------") | ||
fmt.Println("vowels :", vowels) | ||
fmt.Println("digits :", digits) | ||
fmt.Println("symbols :", symbols) | ||
fmt.Println("words :", words) | ||
} |
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,42 @@ | ||
// Reading data from a file and then print out the summary | ||
// Path to "sample.txt" => src/app/variation/sample.txt relative to project root | ||
|
||
package main | ||
|
||
import ( | ||
"app/utils" | ||
"flag" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
) | ||
|
||
// cleanupInput runs all the validation and bleaching to be applied on the input string | ||
func cleanupInput(inputFileName string) string { | ||
if inputFileName == "" { | ||
log.Fatal("Input file name not provided!") | ||
os.Exit(1) | ||
} | ||
|
||
data, err := ioutil.ReadFile(inputFileName) | ||
if err != nil { | ||
log.Fatal("Error => ", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
return string(data) | ||
} | ||
|
||
func main() { | ||
inputFileName := flag.String("file", "", "File to parse") | ||
flag.Parse() | ||
|
||
cleanedStr := cleanupInput(*inputFileName) | ||
|
||
vowels := utils.FindVowels(cleanedStr) | ||
digits := utils.FindDigits(cleanedStr) | ||
symbols := utils.FindSymbols(cleanedStr) | ||
words := utils.FindWords(cleanedStr) | ||
|
||
utils.PrintReport(vowels, digits, symbols, words) | ||
} |
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,5 @@ | ||
This is some sample text for reading from a file. | ||
|
||
More information .. 1 | ||
More information .. 2 | ||
More information .. 3 |