-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for loading of simple lists.
- Loading branch information
Showing
5 changed files
with
191 additions
and
75 deletions.
There are no files selected for viewing
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
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
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
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,55 @@ | ||
library(alabaster.base) | ||
PATH <- "objects" | ||
dir.create(PATH, showWarnings=FALSE) | ||
library(S4Vectors) | ||
|
||
{ | ||
df <- list( | ||
strings = "A", | ||
integers = 1:3, | ||
numbers = 4:6/2, | ||
booleans = FALSE, | ||
factors = factor("Z"), | ||
nothing = NULL | ||
) | ||
|
||
path <- file.path(PATH, "list-basic") | ||
unlink(path, recursive=TRUE) | ||
dir.create(path) | ||
|
||
saveObject(df, file.path(path, "js")) | ||
saveObject(df, file.path(path, "h5"), list.format='hdf5') | ||
} | ||
|
||
{ | ||
df <- list( | ||
strings = c("a", NA_character_), | ||
integers = c(1L, NA, 2L), | ||
numbers = c(3.5, NA, 4.5), | ||
booleans = c(NA, TRUE), | ||
factors = factor(c("Z", NA, "A")) | ||
) | ||
|
||
path <- file.path(PATH, "list-missing") | ||
unlink(path, recursive=TRUE) | ||
dir.create(path) | ||
|
||
saveObject(df, file.path(path, "js")) | ||
saveObject(df, file.path(path, "h5"), list.format='hdf5') | ||
} | ||
|
||
{ | ||
df <- list( | ||
named = list(A = 1L, B = 2L), | ||
unnamed = list("X", "Y", "Z"), | ||
other = DataFrame(B = 2) | ||
) | ||
|
||
path <- file.path(PATH, "list-nested") | ||
unlink(path, recursive=TRUE) | ||
dir.create(path) | ||
|
||
saveObject(df, file.path(path, "js")) | ||
saveObject(df, file.path(path, "h5"), list.format='hdf5') | ||
} | ||
|
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,51 @@ | ||
import * as list from "../../src/readers/list.js"; | ||
import { localNavigator } from "../utils.js"; | ||
import * as path from "path"; | ||
import * as scran from "scran.js"; | ||
|
||
beforeAll(async () => { await scran.initialize({ localFile: true }) }); | ||
afterAll(async () => { await scran.terminate() }); | ||
|
||
const PATH = "objects"; | ||
|
||
test("basic list loading works as expected", async () => { | ||
const basic_list = await list.readSimpleList(path.join(PATH, "list-basic", "js"), localNavigator); | ||
expect(Object.keys(basic_list)).toEqual(["strings", "integers", "numbers", "booleans", "factors", "nothing" ]); | ||
|
||
expect(basic_list["strings"]).toEqual(["A"]); | ||
expect(basic_list["integers"]).toEqual(new Int32Array([1,2,3])); | ||
expect(basic_list["numbers"]).toEqual(new Float64Array([2,2.5,3])); | ||
expect(basic_list["booleans"]).toEqual([false]); | ||
expect(basic_list["factors"]).toEqual(["Z"]); | ||
expect(basic_list["nothing"]).toBeNull(); | ||
|
||
const basic_list_h5 = await list.readSimpleList(path.join(PATH, "list-basic", "h5"), localNavigator); | ||
expect(basic_list_h5).toEqual(basic_list); | ||
}) | ||
|
||
test("list loading works with missing values", async () => { | ||
const missing_list = await list.readSimpleList(path.join(PATH, "list-missing", "js"), localNavigator); | ||
expect(Object.keys(missing_list)).toEqual(["strings", "integers", "numbers", "booleans", "factors" ]); | ||
|
||
expect(missing_list["strings"]).toEqual(["a", null]); | ||
expect(missing_list["integers"]).toEqual([1,null,2]); | ||
expect(missing_list["numbers"]).toEqual([3.5,null,4.5]); | ||
expect(missing_list["booleans"]).toEqual([null, true]); | ||
expect(missing_list["factors"]).toEqual(["Z", null, "A"]); | ||
|
||
const missing_list_h5 = await list.readSimpleList(path.join(PATH, "list-missing", "h5"), localNavigator); | ||
expect(missing_list_h5).toEqual(missing_list); | ||
}) | ||
|
||
test("list loading works with nesting", async () => { | ||
const nested_list = await list.readSimpleList(path.join(PATH, "list-nested", "js"), localNavigator); | ||
expect(Object.keys(nested_list)).toEqual(["named", "unnamed", "other"]); | ||
|
||
expect(nested_list["named"]).toEqual({ A: new Int32Array([1]), B: new Int32Array([2]) }); | ||
expect(nested_list["unnamed"]).toEqual([["X"], ["Y"], ["Z"]]); | ||
expect(nested_list["other"]).toBeNull(); | ||
|
||
const nested_list_h5 = await list.readSimpleList(path.join(PATH, "list-nested", "h5"), localNavigator); | ||
expect(nested_list_h5).toEqual(nested_list); | ||
}) | ||
|