Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Commits
1434b4c3
Commit
1434b4c3
authored
3 years ago
by
Sören Henning
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into concepts-docs
parents
9d37f3be
b15061bb
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!205
Add docs for fundamental concepts
Changes
41
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
theodolite/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt
+46
-1
46 additions, 1 deletion
...te/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt
with
46 additions
and
1 deletion
theodolite/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt
+
46
−
1
View file @
1434b4c3
...
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test
...
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test
import
org.junit.rules.TemporaryFolder
import
org.junit.rules.TemporaryFolder
import
org.junitpioneer.jupiter.ClearEnvironmentVariable
import
org.junitpioneer.jupiter.ClearEnvironmentVariable
import
org.junitpioneer.jupiter.SetEnvironmentVariable
import
org.junitpioneer.jupiter.SetEnvironmentVariable
import
java.util.stream.Collectors
const
val
FOLDER_URL
=
"Test-Folder"
const
val
FOLDER_URL
=
"Test-Folder"
...
@@ -42,12 +43,13 @@ internal class IOHandlerTest {
...
@@ -42,12 +43,13 @@ internal class IOHandlerTest {
temporaryFolder
.
create
()
temporaryFolder
.
create
()
val
folder
=
temporaryFolder
.
newFolder
(
FOLDER_URL
)
val
folder
=
temporaryFolder
.
newFolder
(
FOLDER_URL
)
val
columns
=
listOf
(
"Fruit"
,
"Color"
)
val
testContent
=
listOf
(
val
testContent
=
listOf
(
listOf
(
"apples"
,
"red"
),
listOf
(
"apples"
,
"red"
),
listOf
(
"bananas"
,
"yellow"
),
listOf
(
"bananas"
,
"yellow"
),
listOf
(
"avocado"
,
"brown"
)
listOf
(
"avocado"
,
"brown"
)
)
)
val
columns
=
listOf
(
"Fruit"
,
"Color"
)
IOHandler
().
writeToCSVFile
(
IOHandler
().
writeToCSVFile
(
fileURL
=
"${folder.absolutePath}/test-file"
,
fileURL
=
"${folder.absolutePath}/test-file"
,
...
@@ -65,6 +67,49 @@ internal class IOHandlerTest {
...
@@ -65,6 +67,49 @@ internal class IOHandlerTest {
)
)
}
}
/**
* Tests if values with commas and quotation marks are surrounded with additional quotation marks.
*/
@Test
fun
testWriteToCSVFileWithComma
()
{
temporaryFolder
.
create
()
val
folder
=
temporaryFolder
.
newFolder
(
FOLDER_URL
)
val
columns
=
listOf
(
"Fruit, Fruit2"
,
"Color"
)
val
expectedColumns
=
listOf
(
"\"Fruit, Fruit2\""
,
"Color"
)
val
testContent
=
listOf
(
listOf
(
"apples, "
+
'"'
+
"paprika"
+
'"'
,
"red"
),
listOf
(
"bananas, pineapple"
,
"yellow"
),
listOf
(
"avocado, coconut"
,
"brown"
)
)
val
expectedContent
=
listOf
(
listOf
(
"\"apples, "
+
'"'
+
'"'
+
"paprika"
+
'"'
+
'"'
+
'"'
,
"red"
),
listOf
(
"\"bananas, pineapple\""
,
"yellow"
),
listOf
(
"\"avocado, coconut\""
,
"brown"
)
)
IOHandler
().
writeToCSVFile
(
fileURL
=
"${folder.absolutePath}/test-file"
,
data
=
testContent
,
columns
=
columns
)
// construct string from the columns
var
expected
=
expectedColumns
.
stream
().
collect
(
Collectors
.
joining
(
","
))
// add values from the expectedContent to expected string
expectedContent
.
forEach
{
expected
+=
"\n"
+
it
.
joinToString
(
separator
=
","
)
}
assertEquals
(
expected
,
IOHandler
().
readFileAsString
(
"${folder.absolutePath}/test-file.csv"
)
)
}
@Test
@Test
fun
testWriteToJSONFile
()
{
fun
testWriteToJSONFile
()
{
temporaryFolder
.
create
()
temporaryFolder
.
create
()
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
3
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment