本文整理汇总了TypeScript中chance.integer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript integer函数的具体用法?TypeScript integer怎么用?TypeScript integer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了integer函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generateNeeds
function generateNeeds(): any {
let skillIds = Object.keys(store.skillMap);
let projectIds = Object.keys(store.projectMap);
let needMap: any = {};
for (let i = 0; i < 50; i++) {
let id = nextId++;
// Set start date to Monday this week + random number of weeks
var numWeeksAfter = chance.integer({ min: 0, max: 26 });
var startDate = moment().weekday(1).startOf('day').add(numWeeksAfter, 'weeks');
// Set duration to a random number of weeks
var numWeeksDuration = chance.integer({ min: 1, max: 26 });
var endDate = startDate.clone().add(numWeeksDuration - 1, 'weeks').add(4, 'days').endOf('day');
needMap[id] = {
id: id,
startDate: startDate.toDate(),
endDate: endDate.toDate(),
projectId: parseInt(chance.pick(projectIds)),
skillId: parseInt(chance.pick(skillIds)),
personId: null,
};
};
return needMap;
}
示例2: beforeEach
beforeEach(() => {
config = {
host: '127.0.0.1',
maxPayload: new ByteSizeValue(1024),
port: chance.integer({ min: 10000, max: 15000 }),
ssl: {
enabled: true,
redirectHttpFromPort: chance.integer({ min: 20000, max: 30000 }),
},
} as HttpConfig;
server = new HttpsRedirectServer(loggingServiceMock.create().get());
});
示例3: it
it('should create the specified number of tokens', async () => {
const numTokens = chance.integer({ min: 1, max: 20 });
const tokensFromApi = await tokensLib.createEnrollmentTokens(framework.internalUser, numTokens);
expect(tokensFromApi.length).toEqual(numTokens);
expect(tokensFromApi).toEqual(tokensDB.map((t: TokenEnrollmentData) => t.token));
});
示例4:
const generateRandomContentOutput = () => {
return {
address: chance.string(),
content_type: chance.string(),
size: chance.integer()
};
};
示例5: beforeEach
beforeEach(() => {
config = {
host: '127.0.0.1',
maxPayload: new ByteSizeValue(1024),
port: chance.integer({ min: 10000, max: 15000 }),
ssl: {},
} as HttpConfig;
server = new HttpServer(logger.get());
});
示例6:
const generateLedger = (): ILedgerInput => {
return {
name: chance.name(),
author_id: chance.guid(),
resource_address: chance.guid(),
resource_content_type: ContentType.OCTETSTREAM,
resource_size: chance.integer({min: 1, max: 25000}),
tags: [chance.string(), chance.string()].sort()
};
};
示例7: beforeEach
beforeEach(async () => {
validEnrollmentToken = chance.word();
beatId = chance.word();
beatsDB = [];
tagsDB = [];
tokensDB = [
{
expires_on: moment()
.add(4, 'hours')
.toJSON(),
token: validEnrollmentToken,
},
];
const version =
chance.integer({ min: 1, max: 10 }) +
'.' +
chance.integer({ min: 1, max: 10 }) +
'.' +
chance.integer({ min: 1, max: 10 });
beat = {
host_name: 'foo.bar.com',
type: 'filebeat',
version,
};
const framework = new HapiBackendFrameworkAdapter(settings);
tokensLib = new CMTokensDomain(new MemoryTokensAdapter(tokensDB), {
framework,
});
const tagsLib = new CMTagsDomain(new MemoryTagsAdapter(tagsDB));
beatsLib = new CMBeatsDomain(new MemoryBeatsAdapter(beatsDB), {
tags: tagsLib,
tokens: tokensLib,
framework,
});
});
示例8: test
test('throws if SSL is not enabled', async () => {
await expect(
server.start({
...config,
ssl: {
enabled: false,
redirectHttpFromPort: chance.integer({ min: 20000, max: 30000 }),
},
} as HttpConfig)
).rejects.toMatchSnapshot();
});
示例9: describe
describe("Ledgers", () => {
const chance = new Chance();
const body = {
name: chance.name(),
resource_address: chance.string(),
resource_size: chance.integer({min: 1, max: 25000}),
resource_content_type: chance.string(),
author_id: chance.guid(),
tags: [
chance.string()
]
};
const generateRandomLedgerOutput = () => {
return { ...body,
resource_id: chance.guid()
};
};
const getResponse = generateRandomLedgerOutput();
const postResponse = generateRandomLedgerOutput();
const putResponse = generateRandomLedgerOutput();
const service = new Ledgers(mockHttp(getResponse, postResponse, putResponse) as Http, chance.url());
describe("get", () => {
it("should call http GET and return expected response", async () => {
const response = await service.get(chance.guid());
expect(response).toEqual(getResponse);
});
});
describe("getall", () => {
it("should call http GET and return expected response", async () => {
const response = await service.getAll(chance.guid());
expect(response).toEqual(getResponse);
});
});
describe("post", () => {
it("should call http POST and return expected response", async () => {
const response = await service.post(body);
expect(response).toEqual(postResponse.resource_id);
});
});
describe("put", () => {
it("should call http PUT and return expected response", async () => {
const response = await service.put(chance.guid(), body);
expect(response).toEqual(putResponse.resource_id);
});
});
});