add sample 2
This commit is contained in:
parent
9ced30ded5
commit
d293ac3aa4
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,10 +3,10 @@
|
|||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# Lock File
|
# Lock File
|
||||||
yarn.lock
|
**/yarn.lock
|
||||||
|
|
||||||
# Node Modules
|
# Node Modules
|
||||||
node_modules
|
**/node_modules
|
||||||
|
|
||||||
# Built
|
# Built
|
||||||
dist
|
dist
|
||||||
|
6
example/index.js
Normal file
6
example/index.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const { sample } = require("lib-name")
|
||||||
|
|
||||||
|
console.log("Example : ")
|
||||||
|
console.log("==========================")
|
||||||
|
console.log("Result of 2 = ", sample(2))
|
||||||
|
console.log("Result of 4 = ", sample(4))
|
14
example/package.json
Normal file
14
example/package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "lib-example",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Example of Develop Library",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": false,
|
||||||
|
"dependencies": {
|
||||||
|
"lib-name": "link:../"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"build:test": "yarn jest && yarn build"
|
"build:test": "yarn jest && yarn build",
|
||||||
|
"run:example": "cd example && yarn start"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.11.4",
|
"@babel/core": "^7.11.4",
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
export { default as sample } from "./sample"
|
export { default as power } from "./sample"
|
||||||
|
|
||||||
|
export { default as sqrt } from "./sample2"
|
||||||
|
11
src/sample2.ts
Normal file
11
src/sample2.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const sqrt = (n : number): number | undefined => {
|
||||||
|
if( typeof n === "undefined" || n === null){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
if(typeof n !== "number"){
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return Math.sqrt(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default sqrt
|
@ -1,25 +1,25 @@
|
|||||||
import {sample} from "../src"
|
import {power} from "../src"
|
||||||
|
|
||||||
// Describe : top level to describe a block of test below is for what
|
// Describe : top level to describe a block of test below is for what
|
||||||
describe("Test Sample Function", () => {
|
describe("Test Sample Function", () => {
|
||||||
// Test : is run for each test
|
// Test : is run for each test
|
||||||
test("Test N is Undefined", () => {
|
test("Test N is Undefined", () => {
|
||||||
expect(sample(undefined)).toBe(undefined) // expect sample(undefined) return undefined
|
expect(power(undefined)).toBe(undefined) // expect sample(undefined) return undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Test N is Null", () => {
|
test("Test N is Null", () => {
|
||||||
expect(sample(null)).toBe(undefined)
|
expect(power(null)).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Test N is not number",() => {
|
test("Test N is not number",() => {
|
||||||
expect(sample("Hello")).toBe(undefined)
|
expect(power("Hello")).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Test Normal Number",() => {
|
test("Test Normal Number",() => {
|
||||||
expect(sample(0)).toBe(0)
|
expect(power(0)).toBe(0)
|
||||||
expect(sample(1)).toBe(1)
|
expect(power(1)).toBe(1)
|
||||||
expect(sample(2)).toBe(4)
|
expect(power(2)).toBe(4)
|
||||||
expect(sample(100)).toBe(10000)
|
expect(power(100)).toBe(10000)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
25
test/sample2.test.js
Normal file
25
test/sample2.test.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import {sqrt} from "../src"
|
||||||
|
|
||||||
|
// Describe : top level to describe a block of test below is for what
|
||||||
|
describe("Test Sample 2 Function", () => {
|
||||||
|
// Test : is run for each test
|
||||||
|
test("Test N is Undefined", () => {
|
||||||
|
expect(sqrt(undefined)).toBe(undefined) // expect sample(undefined) return undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Test N is Null", () => {
|
||||||
|
expect(sqrt(null)).toBe(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Test N is not number",() => {
|
||||||
|
expect(sqrt("Hello")).toBe(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("Test Normal Number",() => {
|
||||||
|
expect(sqrt(0)).toBe(0)
|
||||||
|
expect(sqrt(1)).toBe(1)
|
||||||
|
expect(sqrt(4)).toBe(2)
|
||||||
|
expect(sqrt(10000)).toBe(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user