Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruby code sample for test (#40) #45

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
ChandanChainani marked this conversation as resolved.
Show resolved Hide resolved
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]