-
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
1 parent
e390080
commit b2f8b55
Showing
23 changed files
with
833 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,31 @@ | ||
package Cats | ||
import ( | ||
"fmt" | ||
"encoding/xml" | ||
) | ||
|
||
type Cat struct{ | ||
XMLName xml.Name `xml:"cat"` | ||
Health int `xml:"health"` | ||
Name string `xml:"name"` | ||
Color string `xml:"color"` | ||
} | ||
|
||
func(c Cat) String() string{ | ||
return fmt.Sprintf("%s\n%v\n%s",c.Name, c.Health, c.Color) | ||
} | ||
|
||
type Cats struct{ | ||
XMLName xml.Name `xml:"Data"` | ||
Cats []Cat `xml:"cat"` | ||
} | ||
|
||
func (data Cats) String() string{ | ||
var result string | ||
for _, v := range data.Cats{ | ||
result += v.String() | ||
result +="\n\n" | ||
} | ||
result = result[0:len(result)-1] | ||
return result | ||
} |
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,19 @@ | ||
<xml> | ||
<Colors> | ||
<color>White</color> | ||
<color>Red</color> | ||
<color>Yellow</color> | ||
<color>Green</color> | ||
<color>Black</color> | ||
<color>Orange</color> | ||
<color>Pink</color> | ||
<color>Purple</color> | ||
<color>Brown</color> | ||
<color>Blue</color> | ||
<color>Aqua</color> | ||
<color>Silver</color> | ||
<color>Olive</color> | ||
<color>Gold</color> | ||
<color>Lime</color> | ||
</Colors> | ||
</xml> |
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,19 @@ | ||
package colors | ||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
type Colors struct{ | ||
XMLName xml.Name `xml:"Colors"` | ||
Colors []string `xml:"color"` | ||
} | ||
|
||
func (data Colors) String() string{ | ||
var result string | ||
for _, v := range data.Colors{ | ||
result += v | ||
result +="\n\n" | ||
} | ||
result = result[0:len(result)-1] | ||
return result | ||
} |
Empty file.
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 @@ | ||
This is config |
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,24 @@ | ||
<xml> | ||
<Data> | ||
<cat> | ||
<health>88</health> | ||
<name>Jora</name> | ||
<color>White</color> | ||
</cat> | ||
<cat> | ||
<health>198</health> | ||
<name>German</name> | ||
<color>Red</color> | ||
</cat> | ||
<cat> | ||
<health>46</health> | ||
<name>Blue</name> | ||
<color>Yellow</color> | ||
</cat> | ||
<cat> | ||
<health>68</health> | ||
<name>Blue</name> | ||
<color>Magenta</color> | ||
</cat> | ||
</Data> | ||
</xml> |
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,24 @@ | ||
<xml> | ||
<Data> | ||
<cat> | ||
<health>99</health> | ||
<name>Quaternion</name> | ||
<color>Black</color> | ||
</cat> | ||
<cat> | ||
<health>11</health> | ||
<name>Radius</name> | ||
<color>Brown</color> | ||
</cat> | ||
<cat> | ||
<health>46</health> | ||
<name>HashTable</name> | ||
<color>Green</color> | ||
</cat> | ||
<cat> | ||
<health>90</health> | ||
<name>BitMap</name> | ||
<color>Pink</color> | ||
</cat> | ||
</Data> | ||
</xml> |
Binary file not shown.
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,37 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
"encoding/xml" | ||
"flag" | ||
"go_project/stream" | ||
"go_project/cats" | ||
"go_project/validator" | ||
"go_project/colors" | ||
) | ||
|
||
func flagReadCommandLine(key string, defaultValue string, helpInfo string) string{ | ||
var config = flag.String(key, defaultValue, helpInfo) | ||
flag.Parse() | ||
return *config | ||
} | ||
|
||
func main() { | ||
// config:=flagReadCommandLine("fileName","configXML.xml","set config file name") | ||
var config = flag.String("fileName","configXML.xml","set config file name") | ||
flag.Parse() | ||
content := stream.ReadFile(*config) | ||
var data Cats.Cats | ||
xml.Unmarshal(content, &data) | ||
fmt.Println(data) | ||
|
||
validator.TestAgeAllCats(data) | ||
|
||
fmt.Println() | ||
var colorFlag = flag.String("colorFileName","colors.xml","set color config file name") | ||
colorsFile := stream.ReadFile(*colorFlag) | ||
var ProgrammColors colors.Colors | ||
xml.Unmarshal(colorsFile, &ProgrammColors) | ||
|
||
validator.TestColorAllCats(data ,ProgrammColors) | ||
// stream.Pause() | ||
} |
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 @@ | ||
|
||
func factorial(n int) int { | ||
if n < 2 { | ||
return 1 | ||
|
||
} | ||
return n * factorial(n-1) | ||
} | ||
|
||
func a() { | ||
for i := 0; i < 4; i++ { | ||
defer fmt.Println(i) | ||
} | ||
} | ||
|
||
func sqr(peace int) int { | ||
return peace * peace | ||
} | ||
|
||
package main | ||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"encoding/xml" | ||
) | ||
|
||
type Cat struct{ | ||
XMLName xml.Name `xml:"cat"` | ||
Health int `xml:"health"` | ||
Name string `xml:"name"` | ||
Color string `xml:"color"` | ||
} | ||
|
||
func(c Cat) String() string{ | ||
return fmt.Sprintf("%s\n%v\n%s",c.Name, c.Health, c.Color ) | ||
} | ||
|
||
func catch(err error){ | ||
if err != nil{ | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
content, err := ioutil.ReadFile("configXML.xml") | ||
catch(err) | ||
|
||
var flafy = Cat{Health:100, Name:"flafy", Color:"orange"} | ||
err = xml.Unmarshal(content, &flafy) | ||
catch(err) | ||
fmt.Println(flafy) | ||
} | ||
|
||
go run prog.go -fileName=configXML_new.xml |
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,25 @@ | ||
package stream | ||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"bufio" | ||
"os" | ||
) | ||
|
||
func Catch(err error){ | ||
if err != nil{ | ||
panic(err) | ||
} | ||
} | ||
|
||
func ReadFile(config string) []byte { | ||
content, err := ioutil.ReadFile(config) | ||
Catch(err) | ||
return content | ||
} | ||
|
||
func Pause(){ | ||
fmt.Print("Print enter to exit") | ||
reader := bufio.NewReader(os.Stdin) | ||
reader.ReadString('\n') | ||
} |
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,45 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"go_project/validator" | ||
"go_project/colors" | ||
) | ||
|
||
func TestValidatorAge_AgeIsValid(t *testing.T){ | ||
if(!validator.IsAgeValid(20)){ | ||
t.Error("Validator error", 20, "became invalid, but age valid in [0, 100]") | ||
} | ||
} | ||
|
||
func TestValidatorAge_AgeIsValidToLittle(t *testing.T){ | ||
if(validator.IsAgeValid(-20)){ | ||
t.Error("Validator error", -20, "became valid, but age valid in [0, 100]") | ||
} | ||
} | ||
|
||
func TestValidatorAge_AgeIsInValidToMuch(t *testing.T){ | ||
if(validator.IsAgeValid(120)){ | ||
t.Error("Validator error", 120, "became valid, but age valid in [0, 100]") | ||
} | ||
} | ||
|
||
func TestValidatorColor_ColorIsValid(t *testing.T){ | ||
var color string = "White" | ||
var AllColors colors.Colors | ||
var array []string = []string{"White","Red","Magenta"} | ||
AllColors.Colors = array | ||
if(!validator.IsColorValid(color, AllColors)){ | ||
t.Error("validator error", color, "became invalid, but it must be in valid colors array", AllColors) | ||
} | ||
} | ||
|
||
func TestValidatorColor_ColorIsInValid(t *testing.T){ | ||
var color string = "Green" | ||
var AllColors colors.Colors | ||
var array []string = []string{"White","Red","Magenta"} | ||
AllColors.Colors = array | ||
if(validator.IsColorValid(color, AllColors)){ | ||
t.Error("validator error", color, "became valid, but it must not be in valid colors array\n", AllColors) | ||
} | ||
} |
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,39 @@ | ||
package validator | ||
import ( | ||
"fmt" | ||
"go_project/colors" | ||
"go_project/cats" | ||
) | ||
|
||
func IsAgeValid(age int) bool{ | ||
if (age > 0 && age < 100) {return true} | ||
return false | ||
} | ||
|
||
func TestAgeAllCats(data Cats.Cats){ | ||
fmt.Println(" --- validator ---") | ||
fmt.Println(" - Ages - ") | ||
for i := 0; i < len(data.Cats); i++ { | ||
tempHealth := data.Cats[i].Health | ||
fmt.Printf("%v valid %v",tempHealth,IsAgeValid(tempHealth)) | ||
fmt.Println() | ||
} | ||
} | ||
|
||
func IsColorValid(TestColor string, AllColors colors.Colors) bool{ | ||
for i:= 0; i < len(AllColors.Colors); i++{ | ||
var temp = AllColors.Colors[i] | ||
if (TestColor == temp) {return true} | ||
} | ||
return false | ||
} | ||
|
||
func TestColorAllCats(data Cats.Cats, AllColors colors.Colors){ | ||
fmt.Println(" --- validator ---") | ||
fmt.Println(" - Colors - ") | ||
for i := 0; i < len(data.Cats); i++ { | ||
tempColor := data.Cats[i].Color | ||
fmt.Printf("%s valid %v",tempColor,IsColorValid(tempColor, AllColors)) | ||
fmt.Println() | ||
} | ||
} |