Skip to content

Commit

Permalink
returned everything
Browse files Browse the repository at this point in the history
  • Loading branch information
FIN-THE-HUMAN committed Oct 4, 2017
1 parent e390080 commit b2f8b55
Show file tree
Hide file tree
Showing 23 changed files with 833 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .idea/go_projects.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/libraries/Go_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

490 changes: 490 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file added pkg/windows_amd64/go_project/cats.a
Binary file not shown.
Binary file added pkg/windows_amd64/go_project/colors.a
Binary file not shown.
Binary file added pkg/windows_amd64/go_project/dataTypes.a
Binary file not shown.
Binary file added pkg/windows_amd64/go_project/stream.a
Binary file not shown.
Binary file added pkg/windows_amd64/go_project/tests.a
Binary file not shown.
Binary file added pkg/windows_amd64/go_project/validator.a
Binary file not shown.
31 changes: 31 additions & 0 deletions src/go_project/cats/cats.go
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
}
19 changes: 19 additions & 0 deletions src/go_project/colors.xml
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>
19 changes: 19 additions & 0 deletions src/go_project/colors/colors.go
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 added src/go_project/colors2.xml
Empty file.
1 change: 1 addition & 0 deletions src/go_project/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is config
24 changes: 24 additions & 0 deletions src/go_project/configXML.xml
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>
24 changes: 24 additions & 0 deletions src/go_project/configXML_new.xml
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 added src/go_project/prog.exe
Binary file not shown.
37 changes: 37 additions & 0 deletions src/go_project/prog.go
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()
}
54 changes: 54 additions & 0 deletions src/go_project/rubish.txt
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
25 changes: 25 additions & 0 deletions src/go_project/stream/stream.go
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')
}
45 changes: 45 additions & 0 deletions src/go_project/tests/tests_test.go
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)
}
}
39 changes: 39 additions & 0 deletions src/go_project/validator/validator.go
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()
}
}

0 comments on commit b2f8b55

Please sign in to comment.