Skip to content

Commit

Permalink
Merge new version home_work fnd my version
Browse files Browse the repository at this point in the history
  • Loading branch information
DimVlas authored and DimVlas committed Oct 5, 2024
1 parent 9c57809 commit 2221038
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 166 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.19
go-version: ~1.22

- name: Check out code
uses: actions/checkout@v3

- name: Linters
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: v1.57.2
working-directory: ${{ env.BRANCH }}

tests:
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.19
go-version: ^1.22

- name: Check out code
uses: actions/checkout@v3
Expand All @@ -67,7 +67,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.19
go-version: ^1.22

- name: Check out code
uses: actions/checkout@v3
Expand Down
17 changes: 1 addition & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ linters-settings:
funlen:
lines: 150
statements: 80
depguard:
rules:
main:
list-mode: lax
files:
- $all
- "!$test"
allow:
- $gostd
test:
files:
- "$test"
allow:
- $gostd
- "github.com/stretchr/testify/require"

issues:
exclude-rules:
Expand All @@ -37,10 +22,10 @@ linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- bodyclose
- durationcheck
- errorlint
- exhaustive
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
[Инструкция по сдаче ДЗ](https://github.com/OtusGolang/home_work/wiki#%D0%A1%D1%82%D1%83%D0%B4%D0%B5%D0%BD%D1%82%D0%B0%D0%BC).

---
Используемая версия [golangci-lint](https://golangci-lint.run/usage/install/#other-ci): <b>v1.50.1</b>
Используемая версия [golangci-lint](https://golangci-lint.run/usage/install/#other-ci): <b>v1.57.2</b>
```
$ golangci-lint version
golangci-lint has version 1.50.1 built from 8926a95 on 2022-10-22T10:48:48Z
golangci-lint has version 1.57.2 built with go1.22.1 from 77a8601a on 2024-03-28T19:01:11Z
```

---
Expand Down
4 changes: 2 additions & 2 deletions hw01_hello_otus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Hello, OTUS!
```

Для переворота строки следует воспользоваться возможностями
[golang.org/x/example/stringutil](https://pkg.go.dev/golang.org/x/example/stringutil).
[golang.org/x/example/hello/reverse](https://pkg.go.dev/golang.org/x/example/hello/reverse).

Кроме этого необходимо исправить **go.mod** так, чтобы для данного модуля работала
команда `go get`, а полученный **go.sum** закоммитить.

### Критерии оценки
- Пайплайн зелёный - 4 балла
- Используется `stringutil` - 4 балла
- Используется `reverse` - 4 балла
- Понятность и чистота кода - до 2 баллов

#### Зачёт от 7 баллов
Expand Down
2 changes: 1 addition & 1 deletion hw01_hello_otus/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/DimVlas/otus_hw/hw01_hello_otus

go 1.19
go 1.22

require golang.org/x/example v0.0.0-20230731131755-00c7068f9d83
2 changes: 1 addition & 1 deletion hw02_unpack_string/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw02_unpack_string

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
2 changes: 1 addition & 1 deletion hw03_frequency_analysis/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw03_frequency_analysis

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
4 changes: 2 additions & 2 deletions hw04_lru_cache/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/fixme_my_friend/hw04_lru_cache
module github.com/DimVlas/otus_hw/hw04_lru_cache

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
125 changes: 10 additions & 115 deletions hw04_lru_cache/list.go
Original file line number Diff line number Diff line change
@@ -1,131 +1,26 @@
package hw04lrucache

type List interface {
Len() int // Кол-во элементов в списке.
Front() *ListItem // Первый элемент списка.
Back() *ListItem // Последний элемент списка.
PushFront(v interface{}) *ListItem // Добавление элемента в начало списка.
PushBack(v interface{}) *ListItem // Добавление элемента в конец списка.
Remove(i *ListItem) // Удаление элемента из списка.
MoveToFront(i *ListItem) // Переместить элемент вперед.
Len() int
Front() *ListItem
Back() *ListItem
PushFront(v interface{}) *ListItem
PushBack(v interface{}) *ListItem
Remove(i *ListItem)
MoveToFront(i *ListItem)
}

type ListItem struct {
Value interface{}
Prev *ListItem
Next *ListItem
Prev *ListItem
}

type list struct {
len int
front *ListItem
back *ListItem
List // Remove me after realization.
// Place your code here.
}

// Создать новый двусвязный список.
func NewList() List {
return new(list)
}

// Кол-во элементов в списке.
func (lst *list) Len() int {
return lst.len
}

// Первый элемент списка.
func (lst *list) Front() *ListItem {
return lst.front
}

// Последний элемент списка.
func (lst *list) Back() *ListItem {
return lst.back
}

// Добавление элемента в начало списка.
func (lst *list) PushFront(v interface{}) *ListItem {
itm := &ListItem{
Value: v,
Next: lst.front,
}
lst.front = itm
lst.len++

if itm.Next == nil {
lst.back = itm
return itm
}

itm.Next.Prev = itm
return itm
}

// Добавление элемента в конец списка.
func (lst *list) PushBack(v interface{}) *ListItem {
itm := &ListItem{
Value: v,
Prev: lst.back,
}
lst.back = itm
lst.len++

if itm.Prev == nil {
lst.front = itm
return itm
}

itm.Prev.Next = itm
return itm
}

// Удаление элемента из списка.
func (lst *list) Remove(i *ListItem) {
if i == nil {
return
}

if i.Prev == nil && i.Next == nil { // единственный элемент
lst.front = nil
lst.back = nil
lst.len--
return
}

if i.Prev == nil { // первый элемент
i.Next.Prev = nil
lst.front = i.Next
lst.len--
return
}

if i.Next == nil { // последний элемент
i.Prev.Next = nil
lst.back = i.Prev
lst.len--
return
}

i.Prev.Next = i.Next
i.Next.Prev = i.Prev
lst.len--
}

// Переместить элемент вперед.
func (lst *list) MoveToFront(i *ListItem) {
if i.Prev == nil { // первый элемент
return
}

if i.Next != nil { // элемент из середины
i.Prev.Next = i.Next // предыдущий ссылается на следующий
i.Next.Prev = i.Prev // следующий ссылается на предыдущий
} else { // последний элемент
i.Prev.Next = nil
lst.back = i.Prev
}

i.Prev = nil
i.Next = lst.front
lst.front = i
i.Next.Prev = i
}
2 changes: 1 addition & 1 deletion hw05_parallel_execution/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw05_parallel_execution

go 1.19
go 1.22

require (
github.com/stretchr/testify v1.7.0
Expand Down
3 changes: 2 additions & 1 deletion hw06_pipeline_execution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func Stage(in <-chan interface{}) (out <-chan interface{}) {
### Критерии оценки
- CI-пайплайн зелёный - 5 баллов
- Добавлены новые юнит-тесты - до 2 баллов
- Понятность и чистота кода - до 3 баллов
- Проходит тест TestAllStageStop - 2 балла
- Понятность и чистота кода - до 1 баллов

#### Зачёт от 7 баллов

Expand Down
2 changes: 1 addition & 1 deletion hw06_pipeline_execution/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw06_pipeline_execution

go 1.19
go 1.22

require github.com/stretchr/testify v1.7.0

Expand Down
62 changes: 62 additions & 0 deletions hw06_pipeline_execution/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hw06pipelineexecution

import (
"strconv"
"sync"
"testing"
"time"

Expand All @@ -13,6 +14,8 @@ const (
fault = sleepPerStage / 2
)

var isFullTesting = true

func TestPipeline(t *testing.T) {
// Stage generator
g := func(_ string, f func(v interface{}) interface{}) Stage {
Expand Down Expand Up @@ -136,6 +139,65 @@ func TestPipeline(t *testing.T) {
})
}

func TestAllStageStop(t *testing.T) {
if !isFullTesting {
return
}
wg := sync.WaitGroup{}
// Stage generator
g := func(_ string, f func(v interface{}) interface{}) Stage {
return func(in In) Out {
out := make(Bi)
wg.Add(1)
go func() {
defer wg.Done()
defer close(out)
for v := range in {
time.Sleep(sleepPerStage)
out <- f(v)
}
}()
return out
}
}

stages := []Stage{
g("Dummy", func(v interface{}) interface{} { return v }),
g("Multiplier (* 2)", func(v interface{}) interface{} { return v.(int) * 2 }),
g("Adder (+ 100)", func(v interface{}) interface{} { return v.(int) + 100 }),
g("Stringifier", func(v interface{}) interface{} { return strconv.Itoa(v.(int)) }),
}

t.Run("done case", func(t *testing.T) {
in := make(Bi)
done := make(Bi)
data := []int{1, 2, 3, 4, 5}

// Abort after 200ms
abortDur := sleepPerStage * 2
go func() {
<-time.After(abortDur)
close(done)
}()

go func() {
for _, v := range data {
in <- v
}
close(in)
}()

result := make([]string, 0, 10)
for s := range ExecutePipeline(in, done, stages...) {
result = append(result, s.(string))
}
wg.Wait()

require.Len(t, result, 0)

})
}

func TestChanWrap(t *testing.T) {
t.Run("To end", func(t *testing.T) {
in := make(Bi)
Expand Down
2 changes: 1 addition & 1 deletion hw07_file_copying/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DimVlas/otus_hw/hw07_file_copying

go 1.19
go 1.22

require github.com/stretchr/testify v1.9.0

Expand Down
Loading

0 comments on commit 2221038

Please sign in to comment.