Ad
  • Custom User Avatar

    Random tests are failing. I have run some of those falling tests on the local machine and they are passed.
    But tests with the same values fail on the web.

    //My solution
    func CreateIterator(fn func(int) int, n int) func(int) int {
    var f = func(v int) int {
    return fn(v) * n
    }
    return f
    }

    //Some tests
    func TestCreateIterator(t *testing.T) {
    type args struct {
    fn func(int) int
    val int
    times int
    }
    tests := []struct {
    name string
    args args
    want int
    }{
    {"Test 1", args{func(val int) int { return val * 2},2, 2}, 8},
    {"Test 2", args{func(val int) int { return (val + 14) * 7},213, 7},11123},
    {"Test 3", args{func(val int) int { return (40 - val) * 5},77, 3},-555},
    {"Test 4", args{func(val int) int { return (10 - val) * 9},27, 2},-306},
    }
    for _, tt := range tests {
    t.Run(tt.name, func(t *testing.T) {
    var fn = CreateIterator(tt.args.fn, tt.args.times)
    var got = fn(tt.args.val)
    assert.Equal(t,tt.want, got)
    })
    }
    }

  • Custom User Avatar

    Hey folks! Does anybody knows does Morse dictionary exist for GO exacltly for this task or I should use some third party lib?