This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse test data and convert to Map / List of Map
- Loading branch information
Showing
2 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
20 changes: 8 additions & 12 deletions
20
src/main/scala/net/srirangan/sortablechallenge/parsers/TestDataParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
package net.srirangan.sortablechallenge.parsers | ||
|
||
object TestDataParser { | ||
import util.parsing.json.JSON | ||
|
||
def parse(filePath: String): List[String] = { | ||
// Read file per line | ||
// Convert line into map | ||
// Append map to result list | ||
// return | ||
null | ||
} | ||
object TestDataParser { | ||
|
||
private def parseObject(string: String): Map[String, String] = { | ||
// JSON object to map | ||
// return | ||
null | ||
def parse(lines: Iterator[String]): List[Any] = { | ||
var result: List[Any] = List() | ||
lines.foreach((line: String) => { | ||
result ::= JSON.parseFull(line) | ||
}) | ||
result | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/scala/net/srirangan/sortablechallenge/parser/TestDataParserSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.srirangan.sortablechallenge.parser | ||
|
||
import org.scalatest.FunSuite | ||
import org.scalatest.BeforeAndAfter | ||
import net.srirangan.sortablechallenge.parsers.TestDataParser | ||
import io.BufferedSource | ||
|
||
class TestDataParserSuite extends FunSuite with BeforeAndAfter { | ||
|
||
var productsFile: BufferedSource = scala.io.Source.fromFile("/home/srirangan/Projects/sortable-challenge/src/test/resources/products.txt") | ||
var listingsFile: BufferedSource = scala.io.Source.fromFile("/home/srirangan/Projects/sortable-challenge/src/test/resources/listings.txt") | ||
|
||
test("Parse and verifiy test data") { | ||
val lines: Iterator[String] = productsFile.getLines() | ||
TestDataParser.parse(lines) | ||
} | ||
|
||
after { | ||
productsFile.close() | ||
listingsFile.close() | ||
} | ||
|
||
} |