Skip to content

Commit

Permalink
Add ruby code sample for test (#40) (#45)
Browse files Browse the repository at this point in the history
* Add ruby code sample for test (#40)

* Added information in ruby file

* Update scanner test as per ruby file changes

* Update comment block in ruby file

* Updated scanner test as per ruby file changes
  • Loading branch information
ChandanChainani authored Oct 9, 2022
1 parent b10da78 commit 28c6467
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func TestMatchingFiles(t *testing.T) {
Extension: ".py",
Language: "Python",
},
{
FilePath: filepath.Join(codeSamplesDir, "main.rb"),
Extension: ".rb",
Language: "Ruby",
},
},
},
{
Expand Down Expand Up @@ -134,6 +139,11 @@ func TestMatchingFiles(t *testing.T) {
Extension: ".py",
Language: "Python",
},
{
FilePath: filepath.Join(codeSamplesDir, "main.rb"),
Extension: ".rb",
Language: "Ruby",
},
},
},
{
Expand Down Expand Up @@ -181,6 +191,11 @@ func TestMatchingFiles(t *testing.T) {
Extension: ".py",
Language: "Python",
},
{
FilePath: filepath.Join(codeSamplesDir, "main.rb"),
Extension: ".rb",
Language: "Ruby",
},
},
},
{
Expand Down
12 changes: 12 additions & 0 deletions pkg/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func TestScan(t *testing.T) {
Extension: ".py",
Language: "Python",
},
{
FilePath: filepath.Join(codeSamplesDir, "main.rb"),
Extension: ".rb",
Language: "Ruby",
},
}

expected := []scanResult{
Expand Down Expand Up @@ -122,6 +127,13 @@ func TestScan(t *testing.T) {
BlankLines: 4,
Comments: 7,
},
{
Metadata: files[8],
Lines: 30,
CodeLines: 18,
BlankLines: 4,
Comments: 8,
},
}

result, err := scanner.Scan(files)
Expand Down
30 changes: 30 additions & 0 deletions test/fixtures/code_samples/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=begin
Given an array of 0s and 1s in random order.
Segregate 0s on left side and 1s on right side of the array
=end
def segregate(a)
left, right = 0, a.length - 1
while left < right
# Increment left index while we see 0 at left
while a[left] == 0
left += 1
end

# Decrement right index while we see 1 at right
while a[right] == 1
right -= 1
end

# Exchange arr[left] and arr[right]
if left < right
a[left], a[right] = a[right], a[left]
left += 1
right -= 1
end
end

return a
end

p segregate([1,0,1,1,0,0])
# Output: [0, 0, 0, 1, 1, 1]

0 comments on commit 28c6467

Please sign in to comment.