diff --git a/calculator/kek b/bin/main similarity index 79% rename from calculator/kek rename to bin/main index 3892994..66db86a 100755 Binary files a/calculator/kek and b/bin/main differ diff --git a/bookstore/bookstore.go b/bookstore/bookstore.go deleted file mode 100644 index fd4d797..0000000 --- a/bookstore/bookstore.go +++ /dev/null @@ -1,81 +0,0 @@ -package bookstore - -import ( - "errors" - "fmt" -) - -type Category int - -const ( - CategoryAutobiography Category = iota - CategoryLargePrintRomance - CategoryParticlePhysics -) - -var validCategory = map[Category]bool{ - CategoryAutobiography: true, - CategoryLargePrintRomance: true, - CategoryParticlePhysics: true, -} - -type Book struct { - Title string - Author string - Copies int - ID int - PriceCents int - DiscountPercents int - category Category -} - -type Catalog map[int]Book - -func Buy(b Book) (Book, error) { - if b.Copies == 0 { - return Book{}, errors.New("no copies left") - } - b.Copies -- - return b, nil -} - -func (c Catalog) GetAllBooks() []Book { - result := []Book{} - for _,b := range c { - result = append(result, b) - } - return result -} - -func (c Catalog) GetBook(ID int) (Book, error) { - b, ok := c[ID] - if !ok { - return Book{}, fmt.Errorf("book with ID %d not found", ID) - } - return b, nil -} - -func (b Book) NetPriceCents() int{ - saving := b.PriceCents * b.DiscountPercents/100 - return b.PriceCents - saving -} - -func (b *Book) SetPriceCents(price int) (error) { - if price < 0 { - return fmt.Errorf("negative price %d", price) - } - b.PriceCents = price - return nil -} - -func (b *Book) SetCategory(category Category) error { - if !validCategory[category] { - return fmt.Errorf("unknown category %q", category) - } - b.category = category - return nil -} - -func (b Book) Category() Category { - return b.category -} \ No newline at end of file diff --git a/bookstore/bookstore_test.go b/bookstore/bookstore_test.go deleted file mode 100644 index 851a4d7..0000000 --- a/bookstore/bookstore_test.go +++ /dev/null @@ -1,134 +0,0 @@ -package bookstore_test - -import ( - "bookstore" - "testing" - "sort" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" -) - -func TestBuy(t *testing.T) { - t.Parallel() - b := bookstore.Book{ - Title: "Lol", - Author: "KEK", - Copies: 2, - } - want := 1 - result,err := bookstore.Buy(b) - if err != nil { - t.Fatal(err) - } - got := result.Copies - if want != got { - t.Errorf("Want %d but got %d", want,got) - } -} - -func TestBuyOutOfStock(t *testing.T) { - t.Parallel() - b := bookstore.Book{ - Title: "Lol", - Author: "KEK", - Copies: 0, - } - _,err := bookstore.Buy(b) - if err == nil { - t.Error("Book is out of stock") - } -} - -func TestGetAllBooks(t *testing.T) { - t.Parallel() - catalog := bookstore.Catalog{ - 1: {ID: 1, Title: "For the Love of Go"}, - 2: {ID: 2, Title: "The Power of Go: Tools"}, - } - want := []bookstore.Book{ - {ID: 1, Title: "For the Love of Go"}, - {ID: 2, Title: "The Power of Go: Tools"}, - } - got := catalog.GetAllBooks() - sort.Slice(got, func(i, j int) bool { - return got[i].ID < got[j].ID - }) - if !cmp.Equal(want, got,cmpopts.IgnoreUnexported(bookstore.Book{})) { - t.Error(cmp.Diff(want, got,)) - } -} -func TestGetBook(t *testing.T) { - t.Parallel() - catalog := bookstore.Catalog{ - 1: {ID: 1, Title: "For the Love of Go"}, - 2: {ID: 2, Title: "The Power of Go: Tools"}, - } - // want := bookstore.Book{ID: 2, Title: "The Power of Go: Tools"} - _, err := catalog.GetBook(2) - if err != nil { - t.Fatal("want error for non-existent ID, got nil") - } -} -func TestNetPriceCents(t *testing.T) { - t.Parallel() - b := bookstore.Book { - Title: "For the love of Go", - PriceCents: 4000, - DiscountPercents: 25, - } - want := 3000 - got := b.NetPriceCents() - if want != got { - t.Errorf("want %d, got %d",want,got) - } -} -func TestSetPriceCents(t *testing.T) { - t.Parallel() - b := bookstore.Book{ - Title: "For the Love of Go", - PriceCents: 4000, - } - want := 3000 - err := b.SetPriceCents(want) - if err != nil { - t.Fatal(err) - } - got := b.PriceCents - if want != got { - t.Errorf("want updated price %d, got %d", want, got) - } -} -func TestSetCategory(t *testing.T) { - t.Parallel() - b := bookstore.Book{ - Title: "For the Love of Go", - } - cats := []bookstore.Category { - bookstore.CategoryAutobiography, - bookstore.CategoryLargePrintRomance, - bookstore.CategoryParticlePhysics, - } - for _, cat := range cats { - err := b.SetCategory(cat) - if err != nil { - t.Fatal(err) - } - got := b.Category() - if cat != got { - t.Errorf("want category %q, got %q", cat, got) - } - } -} - - -func TestSetCategoryInvalid(t *testing.T) { - t.Parallel() - b := bookstore.Book{ - Title: "For the Love of Go", - } - err := b.SetCategory(999) - if err == nil { - t.Fatal("want error for invalid category, got nil") - } -} \ No newline at end of file diff --git a/bookstore/go.mod b/bookstore/go.mod deleted file mode 100644 index 47e349a..0000000 --- a/bookstore/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module bookstore - -go 1.24.4 - -require github.com/google/go-cmp v0.7.0 diff --git a/bookstore/go.sum b/bookstore/go.sum deleted file mode 100644 index 40e761a..0000000 --- a/bookstore/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= diff --git a/bookstore/kek.out b/bookstore/kek.out deleted file mode 100644 index d5977ef..0000000 --- a/bookstore/kek.out +++ /dev/null @@ -1,4 +0,0 @@ -mode: set -bookstore/bookstore.go:13.32,14.19 1 1 -bookstore/bookstore.go:14.19,16.3 1 1 -bookstore/bookstore.go:17.2,18.15 2 1 diff --git a/calculator/calculator.go b/calculator/calculator.go deleted file mode 100755 index 6c5e34d..0000000 --- a/calculator/calculator.go +++ /dev/null @@ -1,25 +0,0 @@ -// Package calculator does simple calculations. -package calculator // Add takes two numbers and returns the result of adding them together. - -import ( - "errors" -) - -func Add(a, b int) int { - return a + b -} - -func Subtract(a, b int) int { - return a - b -} - -func Multiply(a, b int) int { - return a * b -} - -func Divide(a, b int) (int, error) { - if b == 0 { - return 0, errors.New("division by zero not allowed") - } - return a / b, nil -} \ No newline at end of file diff --git a/calculator/calculator_test.go b/calculator/calculator_test.go deleted file mode 100755 index ff32c7d..0000000 --- a/calculator/calculator_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package calculator_test - -import ( - "calculator" - "testing" -) - -func TestAdd(t *testing.T) { - t.Parallel() - - type TestCase struct { - a, b int - want int - } - testCases := []TestCase{ - {a: 2, b: 2, want: 4}, - {a: 5, b: 0, want: 5}, - {a: 1, b: 1, want: 2}, - } - for _, tc := range testCases { - got := calculator.Add(tc.a, tc.b) - if tc.want != got { - t.Errorf("Add(%d, %d): want %d, got %d", tc.a, tc.b, tc.want, got) - } - } -} - -func TestSubtract(t *testing.T) { - t.Parallel() - type testCase struct { - a,b int - want int - } - testCases := []testCase { - {a: 5,b: 3,want: 2}, - {a: 4,b: 3,want: 1}, - {a: 10,b: 3,want: 7}, - } - for _,tc := range testCases { - got := calculator.Subtract(tc.a, tc.b) - if tc.want != got { - t.Errorf("Subtract(%d, %d): want %d, got %d", tc.a,tc.b,tc.want, got) - } - } -} - -func TestMultiply(t *testing.T) { - t.Parallel() - type testCase struct { - a,b int - want int - } - testCases := []testCase { - {a: 5,b: 3,want: 15}, - {a: 4,b: 3,want: 12}, - {a: 10,b: 3,want: 30}, - } - for _,tc := range testCases { - got := calculator.Multiply(tc.a,tc.b) - if tc.want != got { - t.Errorf("Multiply(%d, %d): want %d, got %d", tc.a, tc.b, tc.want, got) - } - } -} - -func TestDivide(t *testing.T) { - t.Parallel() - type testCase struct { - a,b int - want int - } - testCases := []testCase { - {a: 6,b: 3,want: 2}, - {a: 12,b: 3,want: 4}, - {a: 10,b: 2,want: 5}, - } - for _,tc := range testCases { - got,err := calculator.Divide(tc.a,tc.b) - if err != nil { - t.Errorf("WTF r u doing?") - } - if tc.want != got { - t.Errorf("Multiply(%d, %d): want %d, got %d", tc.a, tc.b, tc.want, got) - } - } -} diff --git a/calculator/cmd/calculator/main.go b/calculator/cmd/calculator/main.go deleted file mode 100644 index 96790b4..0000000 --- a/calculator/cmd/calculator/main.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import ( - "calculator" - "fmt" -) - -func main() { - result := calculator.Add(2, 2) - fmt.Println(result) -} diff --git a/calculator/go.mod b/calculator/go.mod deleted file mode 100755 index af2daa6..0000000 --- a/calculator/go.mod +++ /dev/null @@ -1,4 +0,0 @@ -module calculator - -go 1.22.4 - diff --git a/creditcards/creditcards.go b/creditcards/creditcards.go deleted file mode 100644 index b7467b9..0000000 --- a/creditcards/creditcards.go +++ /dev/null @@ -1,19 +0,0 @@ -package creditcards - -import "errors" - - -type card struct { - number string -} - -func New(number string) (card,error) { - if number == "" { - return card{}, errors.New("number must not be empty") - } - return card{number},nil -} - -func (c *card) Number() string { - return c.number -} \ No newline at end of file diff --git a/creditcards/creditcards_test.go b/creditcards/creditcards_test.go deleted file mode 100644 index 8653814..0000000 --- a/creditcards/creditcards_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package creditcards_test - -import ( - "creditcards" - "testing" -) - -func TestNew(t *testing.T) { - t.Parallel() - want := "1234567890" - cc, err := creditcards.New(want) - if err != nil { - t.Fatal(err) - } - got := cc.Number() - if want != got { - t.Errorf("want %q, got %q", want, got) - } -} -func TestNewInvalidReturnsError(t *testing.T) { - t.Parallel() - _, err := creditcards.New("") - if err == nil { - t.Fatal("want error for invalid card number, got nil") - } -} \ No newline at end of file diff --git a/creditcards/go.mod b/creditcards/go.mod deleted file mode 100644 index 632cf99..0000000 --- a/creditcards/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module creditcards - -go 1.24.4 diff --git a/diff/_switch/cmd/switch/__debug_bin1699744996 b/diff/_switch/cmd/switch/__debug_bin1699744996 deleted file mode 100755 index e2db847..0000000 Binary files a/diff/_switch/cmd/switch/__debug_bin1699744996 and /dev/null differ diff --git a/diff/_switch/cmd/switch/main.go b/diff/_switch/cmd/switch/main.go deleted file mode 100644 index ea11128..0000000 --- a/diff/_switch/cmd/switch/main.go +++ /dev/null @@ -1,9 +0,0 @@ -package main - -import ( - "switch/internal/switchpkg" -) - -func main() { - switchpkg.Say("Utii") -} diff --git a/diff/_switch/go.mod b/diff/_switch/go.mod deleted file mode 100644 index e722938..0000000 --- a/diff/_switch/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module switch - -go 1.24.4 diff --git a/diff/_switch/internal/switchpkg/switch.go b/diff/_switch/internal/switchpkg/switch.go deleted file mode 100644 index c076f8a..0000000 --- a/diff/_switch/internal/switchpkg/switch.go +++ /dev/null @@ -1,9 +0,0 @@ -package switchpkg - -import ( - "fmt" -) - -func Say(name string) { - fmt.Printf("Hello %s",name) -} \ No newline at end of file diff --git a/mytypes/go.mod b/mytypes/go.mod deleted file mode 100644 index e74c47a..0000000 --- a/mytypes/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module mytypes - -go 1.24.4 diff --git a/mytypes/mytypes.go b/mytypes/mytypes.go deleted file mode 100644 index d2eb067..0000000 --- a/mytypes/mytypes.go +++ /dev/null @@ -1,35 +0,0 @@ -package mytypes - -import "strings" - -type MyInt int -type MyString string -type MyBuilder struct { - Contents strings.Builder -} - -func (i MyInt) Twice() MyInt { - return i * 2 -} - - -func (i MyString) Len() int { - return len(i) -} - -func (s MyBuilder) Hello() string { - return "Hello, Gophers!" -} - -func (s MyBuilder) Uppers(in string) string { - return strings.ToUpper(in) -} - -func Double(input *int) int{ - *input *= 2 - return *input -} - -func (input *MyInt) Double() { - *input *= 2 -} \ No newline at end of file diff --git a/mytypes/mytypes_test.go b/mytypes/mytypes_test.go deleted file mode 100644 index 0298fe9..0000000 --- a/mytypes/mytypes_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package mytypes_test - -import ( - "mytypes" - "testing" - "strings" -) - -func TestTwice(t *testing.T) { - t.Parallel() - input := mytypes.MyInt(9) - want := mytypes.MyInt(18) - got := input.Twice() - if want != got { - t.Errorf("twice %d: want %d, got %d", input, want, - got) - } -} - -func TestMyStringLen(t *testing.T) { - t.Parallel() - input := mytypes.MyString("lol") - want := 3 - got := input.Len() - if want != got { - t.Errorf("%q: want %d, got %d", input, want, got) - } -} - -func TestStringsBuilder(t *testing.T) { - t.Parallel() - var sb strings.Builder - sb.WriteString("Hello, ") - sb.WriteString("Gophers!") - want := "Hello, Gophers!" - got := sb.String() - if want != got { - t.Errorf("want %q, got %q", want, got) - } - wantLen := 15 - gotLen := sb.Len() - if wantLen != gotLen { - t.Errorf("%q: want len %d, got %d", sb.String(), - wantLen, gotLen) - } -} - -// func TestMyBuilderLen(t *testing.T) { -// t.Parallel() -// var mb mytypes.MyBuilder -// want := 15 -// got := mb.Len() -// if want != got { -// t.Errorf("want %d, got %d", want, got) -// } -// } - -func TestMyBuilderHello(t *testing.T) { - t.Parallel() - var mb mytypes.MyBuilder - want := "Hello, Gophers!" - got := mb.Hello() - if want != got { - t.Errorf("want %q, got %q", want, got) - } -} - -func TestMyBuilder(t *testing.T) { - t.Parallel() - var mb mytypes.MyBuilder - mb.Contents.WriteString("Hello, ") - mb.Contents.WriteString("Gophers!") - want := "Hello, Gophers!" - got := mb.Contents.String() - if want != got { - t.Errorf("want %q, got %q", want, got) - } - wantLen := 15 - gotLen := mb.Contents.Len() - if wantLen != gotLen { - t.Errorf("%q: want len %d, got %d", - mb.Contents.String(), wantLen, gotLen) - } -} - -func TestUpperCase(t *testing.T) { - t.Parallel() - var mb mytypes.MyBuilder - input := "hello" - want := "HELLO" - got := mb.Uppers(input) - if got != want { - t.Errorf("%q: want %s, got %s",input,want,got) - } -} - -func TestDouble(t *testing.T) { - t.Parallel() - x := mytypes.MyInt(12) - want := mytypes.MyInt(24) - p := &x - p.Double() - if want != x { - t.Errorf("want %d, got %d",want,x) - } -} - diff --git a/test-vs-code/main.go b/test-vs-code/main.go deleted file mode 100644 index 0f3d19c..0000000 --- a/test-vs-code/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "fmt" - -func main() { - fmt.Println("hello World") -} diff --git a/vars/cmd/vars/main.go b/vars/cmd/vars/main.go deleted file mode 100644 index 5e91809..0000000 --- a/vars/cmd/vars/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import ( - "test_vars" -) - -func main() { - title := "lolkek" - test_vars.PrintTitle(title) -} diff --git a/vars/go.mod b/vars/go.mod deleted file mode 100644 index 11dbdb9..0000000 --- a/vars/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module test_vars - -go 1.24.4 diff --git a/vars/vars b/vars/vars deleted file mode 100755 index a3815f0..0000000 Binary files a/vars/vars and /dev/null differ diff --git a/vars/vars.go b/vars/vars.go deleted file mode 100644 index 3250e0f..0000000 --- a/vars/vars.go +++ /dev/null @@ -1,9 +0,0 @@ -package test_vars - -import ( - "fmt" -) - -func PrintTitle(title string) { - fmt.Printf("Title is %s\n", title) -} \ No newline at end of file