From 28c6467108ba3f9f893632b7e1b65632536d09d5 Mon Sep 17 00:00:00 2001 From: ChandanChainani Date: Sun, 9 Oct 2022 06:57:16 +0530 Subject: [PATCH] Add ruby code sample for test (#40) (#45) * 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 --- pkg/analyzer/analyzer_test.go | 15 +++++++++++++++ pkg/scanner/scanner_test.go | 12 ++++++++++++ test/fixtures/code_samples/main.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/fixtures/code_samples/main.rb diff --git a/pkg/analyzer/analyzer_test.go b/pkg/analyzer/analyzer_test.go index a53d328..4e96889 100644 --- a/pkg/analyzer/analyzer_test.go +++ b/pkg/analyzer/analyzer_test.go @@ -87,6 +87,11 @@ func TestMatchingFiles(t *testing.T) { Extension: ".py", Language: "Python", }, + { + FilePath: filepath.Join(codeSamplesDir, "main.rb"), + Extension: ".rb", + Language: "Ruby", + }, }, }, { @@ -134,6 +139,11 @@ func TestMatchingFiles(t *testing.T) { Extension: ".py", Language: "Python", }, + { + FilePath: filepath.Join(codeSamplesDir, "main.rb"), + Extension: ".rb", + Language: "Ruby", + }, }, }, { @@ -181,6 +191,11 @@ func TestMatchingFiles(t *testing.T) { Extension: ".py", Language: "Python", }, + { + FilePath: filepath.Join(codeSamplesDir, "main.rb"), + Extension: ".rb", + Language: "Ruby", + }, }, }, { diff --git a/pkg/scanner/scanner_test.go b/pkg/scanner/scanner_test.go index 960dfc7..49e17fe 100644 --- a/pkg/scanner/scanner_test.go +++ b/pkg/scanner/scanner_test.go @@ -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{ @@ -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) diff --git a/test/fixtures/code_samples/main.rb b/test/fixtures/code_samples/main.rb new file mode 100644 index 0000000..2ae7ee9 --- /dev/null +++ b/test/fixtures/code_samples/main.rb @@ -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]