Skip to content

Commit

Permalink
Merge pull request #262 from nfdi4plants/docu
Browse files Browse the repository at this point in the history
Add js unioncase helpers and tests
  • Loading branch information
Freymaurer authored Nov 23, 2023
2 parents 59111d3 + 4df81b9 commit 914e368
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 3 deletions.
1 change: 1 addition & 0 deletions ARCtrl.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "JavaScript", "JavaScript", "{913222CA-261F-49CB-A823-CC7C335F964A}"
ProjectSection(SolutionItems) = preProject
tests\JavaScript\ARCtrl.Index.js = tests\JavaScript\ARCtrl.Index.js
tests\JavaScript\ISA.CompositeCell.js = tests\JavaScript\ISA.CompositeCell.js
tests\JavaScript\ISA.CompositeHeader.js = tests\JavaScript\ISA.CompositeHeader.js
tests\JavaScript\ISA.Person.js = tests\JavaScript\ISA.Person.js
tests\JavaScript\Main.js = tests\JavaScript\Main.js
Expand Down
15 changes: 14 additions & 1 deletion src/ISA/ISA/ArcTypes/CompositeCell.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ type CompositeCell =
match this with
| Term oa -> $"{oa.NameText}"
| FreeText s -> s
| Unitized (v,oa) -> $"{v} {oa.NameText}"
| Unitized (v,oa) -> $"{v} {oa.NameText}"

#if FABLE_COMPILER
//[<CompiledName("Term")>]
static member term (oa:OntologyAnnotation) = CompositeCell.Term(oa)

//[<CompiledName("FreeText")>]
static member freeText (s:string) = CompositeCell.FreeText(s)

//[<CompiledName("Unitized")>]
static member unitized (v:string, oa:OntologyAnnotation) = CompositeCell.Unitized(v, oa)

#else
#endif
76 changes: 75 additions & 1 deletion src/ISA/ISA/ArcTypes/CompositeHeader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@ type IOType =
| _ -> failwith $"Unable to parse combination to existing IOType: `{iotype}`"



#if FABLE_COMPILER

//[<CompiledName("Source")>]
static member source() = IOType.Source

//[<CompiledName("Sample")>]
static member sample() = IOType.Sample

//[<CompiledName("RawDataFile")>]
static member rawDataFile() = IOType.RawDataFile

//[<CompiledName("DerivedDataFile")>]
static member derivedDataFile() = IOType.DerivedDataFile

//[<CompiledName("ImageFile")>]
static member imageFile() = IOType.ImageFile

//[<CompiledName("Material")>]
static member material() = IOType.Material

//[<CompiledName("FreeText")>]
static member freeText(s:string) = IOType.FreeText s

#else
#endif

/// <summary>
/// Model of the different types of Building Blocks in an ARC Annotation Table.
/// </summary>
Expand Down Expand Up @@ -493,4 +520,51 @@ type CompositeHeader =
"Only one output column per table. E.g. experimental samples or files."
| U2.Case1 (FreeText _) | U2.Case2 "FreeText" ->
"Placeholder"
| _ -> failwith $"Unable to parse combination to existing CompositeHeader: `{header}`"
| _ -> failwith $"Unable to parse combination to existing CompositeHeader: `{header}`"

#if FABLE_COMPILER

//[<CompiledName("Component")>]
static member component(oa:OntologyAnnotation) = Component oa

//[<CompiledName("Characteristic")>]
static member characteristic(oa:OntologyAnnotation) = Characteristic oa

//[<CompiledName("Factor")>]
static member factor(oa:OntologyAnnotation) = Factor oa

//[<CompiledName("Parameter")>]
static member parameter(oa:OntologyAnnotation) = Parameter oa

//[<CompiledName("ProtocolType")>]
static member protocolType() = ProtocolType

//[<CompiledName("ProtocolDescription")>]
static member protocolDescription() = ProtocolDescription

//[<CompiledName("ProtocolUri")>]
static member protocolUri() = ProtocolUri

//[<CompiledName("ProtocolVersion")>]
static member protocolVersion() = ProtocolVersion

//[<CompiledName("ProtocolREF")>]
static member protocolREF() = ProtocolREF

//[<CompiledName("Performer")>]
static member performer() = Performer

//[<CompiledName("Date")>]
static member date() = Date

//[<CompiledName("Input")>]
static member input(io:IOType) = Input io

//[<CompiledName("Output")>]
static member output(io:IOType) = Output io

//[<CompiledName("FreeText")>]
static member freeText(s:string) = FreeText s

#else
#endif
27 changes: 27 additions & 0 deletions tests/JavaScript/ISA.CompositeCell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { equal, deepEqual, notEqual } from 'assert';
import { CompositeCell } from "./ARCtrl/ISA/ISA/ArcTypes/CompositeCell.js"
import { OntologyAnnotation } from './ARCtrl/ISA/ISA/JsonTypes/OntologyAnnotation.js';
import { assertEqual } from './ARCtrl/fable_modules/fable-library.4.5.0/Util.js';




describe('CompositeCell', function () {

it('Helper Members', function () {
let oa = OntologyAnnotation.fromString("My OA Name", "NCIT", "http://purl.obolibrary.org/obo/NCIT_C12345")
let t1 = CompositeCell.term(oa)
let t2 = new CompositeCell(0, [oa])
assertEqual(t1, t2);

let ft = "My FreeTextValue"
let ft1 = CompositeCell.freeText(ft)
let ft2 = new CompositeCell(1, [ft])
assertEqual(ft1, ft2);

let v = 5
let u1 = CompositeCell.unitized(5, oa)
let u2 = new CompositeCell(2, [v, oa])
assertEqual(u1, u2);
});
});
96 changes: 95 additions & 1 deletion tests/JavaScript/ISA.CompositeHeader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { equal, deepEqual, notEqual } from 'assert';
import { CompositeHeader, IOType } from "./ARCtrl/ISA/ISA/ArcTypes/CompositeHeader.js"
import { OntologyAnnotation } from './ARCtrl/ISA/ISA/JsonTypes/OntologyAnnotation.js';
import { assertEqual } from './ARCtrl/fable_modules/fable-library.4.5.0/Util.js';

function tests_IOType() {
describe('IOType', function () {
Expand Down Expand Up @@ -42,7 +43,39 @@ function tests_IOType() {
let freetext = new IOType(6, ["My FreeTextValue"])
let asinput = freetext.asInput
equal(asinput, "Input [My FreeTextValue]")
})
});
it('Helper Members', function () {
let so1 = IOType.source()
let so2 = new IOType(0, [])
assertEqual(so1, so2);

let sa1 = IOType.sample()
let sa2 = new IOType(1, [])
assertEqual(sa1, sa2);

let ra1 = IOType.rawDataFile()
let ra2 = new IOType(2, [])
assertEqual(ra1, ra2);

let da1 = IOType.derivedDataFile()
let da2 = new IOType(3, [])
assertEqual(da1, da2);

let im1 = IOType.imageFile()
let im2 = new IOType(4, [])
//let imb = equals(im1, im2);
assertEqual(im1, im2);

let ma1 = IOType.material()
let ma2 = new IOType(5, [])
assertEqual(ma1, ma2);

let ft = "My FreeTextValue"
let ft1 = IOType.freeText(ft)
let ft2 = new IOType(6, [ft])
assertEqual(ft1, ft2);

});
});
}

Expand Down Expand Up @@ -94,4 +127,65 @@ describe('CompositeHeader', function () {
}
}
});
it('Helper Members', function () {
let oa = OntologyAnnotation.fromString("My OA Name", "NCIT", "http://purl.obolibrary.org/obo/NCIT_C12345")
let c1 = CompositeHeader.component(oa)
let c2 = new CompositeHeader(0, [oa])
assertEqual(c1, c2);

let ch1 = CompositeHeader.characteristic(oa)
let ch2 = new CompositeHeader(1, [oa])
assertEqual(ch1, ch2);

let f1 = CompositeHeader.factor(oa)
let f2 = new CompositeHeader(2, [oa])
assertEqual(f1, f2);

let p1 = CompositeHeader.parameter(oa)
let p2 = new CompositeHeader(3, [oa])
assertEqual(p1, p2);

let pt1 = CompositeHeader.protocolType()
let pt2 = new CompositeHeader(4, [])
assertEqual(pt1, pt2);

let pd1 = CompositeHeader.protocolDescription()
let pd2 = new CompositeHeader(5, [])
assertEqual(pd1, pd2);

let pu1 = CompositeHeader.protocolUri()
let pu2 = new CompositeHeader(6, [])
assertEqual(pu1, pu2);

let pv1 = CompositeHeader.protocolVersion()
let pv2 = new CompositeHeader(7, [])
assertEqual(pv1, pv2);

let pr1 = CompositeHeader.protocolREF()
let pr2 = new CompositeHeader(8, [])
assertEqual(pr1, pr2);

let pe1 = CompositeHeader.performer()
let pe2 = new CompositeHeader(9, [])
assertEqual(pe1, pe2);

let d1 = CompositeHeader.date()
let d2 = new CompositeHeader(10, [])
assertEqual(d1, d2);

let iotype = IOType.sample()
let i1 = CompositeHeader.input(iotype)
let i2 = new CompositeHeader(11, [iotype])
assertEqual(i1, i2);

let o1 = CompositeHeader.output(iotype)
let o2 = new CompositeHeader(12, [iotype])
assertEqual(o1, o2);

let ft = "My FreeTextValue"
let ft1 = CompositeHeader.freeText(ft)
let ft2 = new CompositeHeader(13, [ft])
assertEqual(ft1, ft2);

});
});

0 comments on commit 914e368

Please sign in to comment.