Published
Edited
Sep 24, 2020
1 star
Insert cell
md`# NetV@1 TestDoc: Initialization>width & height`
Insert cell
toc()
Insert cell
import { NetV, refresh, getPixelColor, error_color, success_color, warning_color, hex2rgba, rgba2hex, isHexColorSame, isNumberSame, generateAutoTestCaseDescription, generateE2ETestCaseDescription, detectZoom, isStringSameIgnoreQuotesCase } from "@jackieanxis/netv-js-v1-test-document"
Insert cell
import {toc} from "@nebrius/indented-toc"
Insert cell
md`${generateAutoTestCaseDescription(width_100_height_100)}`
Insert cell
width_100_height_100['container']
Insert cell
mutable width_100_height_100 = {
let log = ''
let isPassed = false
let width = 100
let height = 100
let expected = JSON.stringify({ width, height })
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(expected, log)
}
}
Insert cell
md`${generateAutoTestCaseDescription(width_negative_height_100)}`
Insert cell
width_negative_height_100['container']
Insert cell
mutable width_negative_height_100 = {
let log = ''
let isPassed = false
let width = -100
let height = 100
let expected = `RangeError: Cannot set container width with ${width}`
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(expected, log)
}
}
Insert cell
md`${generateAutoTestCaseDescription(width_100_height_0)}`
Insert cell
width_100_height_0['container']
Insert cell
mutable width_100_height_0 = {
let log = ''
let isPassed = false
let width = 100
let height = 0
let expected = `RangeError: Cannot set container height with ${height}`
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(expected, log)
}
}
Insert cell
md`${generateAutoTestCaseDescription(width_unset_height_100)}`
Insert cell
width_unset_height_100['container']
Insert cell
mutable width_unset_height_100 = {
let log = ''
let isPassed = false
let width = 800
let height = 100
let expected = JSON.stringify({ width, height })
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: unset, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(expected, log)
}
}
Insert cell
md`${generateAutoTestCaseDescription(width_100_height_unset)}`
Insert cell
width_100_height_unset['container']
Insert cell
mutable width_100_height_unset = {
let log = ''
let isPassed = false
let width = 100
let height = 600
let expected = JSON.stringify({ width, height })
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: unset`,
container,
log,
expected,
isPassed: isSame(log, expected)
}
}
Insert cell
md`${ generateAutoTestCaseDescription(width_undefined_height_100) }`
Insert cell
width_undefined_height_100['container']
Insert cell
mutable width_undefined_height_100 = {
let log = ''
let isPassed = false
let width = undefined
let height = 100
let expected = `TypeError: Cannot set container width with ${width}`
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
} catch (e) {
log = e.toString()
isPassed = log == expected
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(log, expected)
}
}
Insert cell
md`${ generateAutoTestCaseDescription(width_100_height_null) }`
Insert cell
width_100_height_null['container']
Insert cell
mutable width_100_height_null = {
let log = ''
let isPassed = false
let width = 100
let height = null
let expected = `TypeError: Cannot set container height with ${height}`
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(log, expected)
}
}
Insert cell
md`${ generateAutoTestCaseDescription(width_NaN_height_100) }`
Insert cell
width_NaN_height_100['container']
Insert cell
mutable width_NaN_height_100 = {
let log = ''
let isPassed = false
let width = NaN
let height = 100
let expected = `RangeError: Cannot set container width with ${width}`
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
const canvas = container.querySelector('canvas')
const zoom = detectZoom()
const actualWidth = canvas.width / zoom
const actualHeight = canvas.height / zoom
log = JSON.stringify({
width: actualWidth,
height: actualHeight
})
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(log, expected)
}
}
Insert cell
md`${ generateAutoTestCaseDescription(width_010_height_100) }`
Insert cell
width_010_height_100['container']
Insert cell
mutable width_010_height_100 = {
let log = ''
let isPassed = false
let width = "010"
let height = 100
let expected = `TypeError: Cannot set container width with '010'`
let container = DOM.element('div')
let isSame = (a, b) => {
try {
a = JSON.parse(a)
b = JSON.parse(b)
return isNumberSame(a.width, b.width) && isNumberSame(a.height, b.height)
} catch (e) {
return isStringSameIgnoreQuotesCase(a, b)
}
}
try {
refresh(container)
let netv = new NetV({
container,
width,
height,
backgroundColor: {r: 0, g: 0, b: 0, a: 1}
})
netv.draw()
} catch (e) {
log = e.toString()
}
return {
title: `Width: ${width}, Height: ${height}`,
container,
log,
expected,
isPassed: isSame(log, expected)
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more