1
exercism fetch lua diamond

diamond_spec.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
local diamond = require 'diamond'

describe('diamond', function()
  it('should generate the diamond for A', function()
    assert.are.equal('A\n', diamond('A'))
  end)

  it('should generate the diamond for B', function()
    local expected =
      ' A \n' ..
      'B B\n' ..
      ' A \n'

    assert.are.equal(expected, diamond('B'))
  end)

  it('should generate the diamond for C', function()
    local expected =
      '  A  \n' ..
      ' B B \n' ..
      'C   C\n' ..
      ' B B \n' ..
      '  A  \n'

    assert.are.equal(expected, diamond('C'))
  end)

  it('should generate the diamond for E', function()
    local expected =
      '    A    \n' ..
      '   B B   \n' ..
      '  C   C  \n' ..
      ' D     D \n' ..
      'E       E\n' ..
      ' D     D \n' ..
      '  C   C  \n' ..
      '   B B   \n' ..
      '    A    \n'

    assert.are.equal(expected, diamond('E'))
  end)

  it('should generate the diamond for H', function()
    local expected =
      '       A       \n' ..
      '      B B      \n' ..
      '     C   C     \n' ..
      '    D     D    \n' ..
      '   E       E   \n' ..
      '  F         F  \n' ..
      ' G           G \n' ..
      'H             H\n' ..
      ' G           G \n' ..
      '  F         F  \n' ..
      '   E       E   \n' ..
      '    D     D    \n' ..
      '     C   C     \n' ..
      '      B B      \n' ..
      '       A       \n'

    assert.are.equal(expected, diamond('H'))
  end)
end)