<commit_before>var assert = require('assert');
var usb_driver = require("../usb.js");

var instance = usb_driver.create()

assert.notEqual(instance, undefined, "instance must be undefined");
assert.ok((instance.LIBUSB_CLASS_PER_INTERFACE != undefined), "Constants must be defined");
assert.equal(instance.isLibusbInitalized, false, "isLibusbInitalized must be false");
assert.equal(instance.close(), false, "close() must be false because driver is not opened");

assert.ok(instance.refresh(), "refresh() must be true");
assert.ok(instance.isLibusbInitalized, "isLibusbInitalized must be true after refresh()");

var devices = instance.getDevices(); 
assert.notEqual(devices, undefined, "getDevices() must not be undefined");
assert.ok((devices.length > 0), "getDevices() must be larger than 0 (assume that at least one host controller is available)");

for (var i = 0; i < devices.length; i++) {
	var device = devices[i];
	var deviceDesc = undefined;
	var deviceConfigDesc = undefined;
	assert.ok((device.busNumber > 0), "busNumber must be larger than 0");
	assert.ok((device.deviceAddress > 0), "deviceAddress must be larger than 0");
	var id = device.busNumber + ":" + device.deviceAddress;
	assert.ok(((deviceDesc = device.getDeviceDescriptor()) != undefined), "getDeviceDescriptor() must return an object");
	assert.ok(((deviceConfigDesc = device.getConfigDescriptor()) != undefined), "getConfigDescriptor() must return an object");

	var arr = instance.find_by_vid_and_pid(deviceDesc.idVendor, deviceDesc.idProduct);
	console.log(arr);
	assert.ok((arr != undefined), "usb.find_by_vid_and_pid() must return array");
	assert.ok((arr.length > 0), "usb.find_by_vid_and_pid() must return array with length > 0");
	assert.equal(device.busNumber, arr[0].busNumber, "arr[0] must contain object with same busNumber");
	assert.equal(device.deviceAddress, arr[0].deviceAddress, "arr[0] must contain object with same deviceAddress");

//	assert.equal(device.close(), true, "close() must be true because device is opened by prior 
}
assert.ok(instance.close());

console.log("Tests were successful :-)");
<commit_msg>Test no longer fails if more than one device is found<commit_after>var assert = require('assert');
var usb_driver = require("../usb.js");

var instance = usb_driver.create()

assert.notEqual(instance, undefined, "instance must be undefined");
assert.ok((instance.LIBUSB_CLASS_PER_INTERFACE != undefined), "Constants must be defined");
assert.equal(instance.isLibusbInitalized, false, "isLibusbInitalized must be false");
assert.equal(instance.close(), false, "close() must be false because driver is not opened");

assert.ok(instance.refresh(), "refresh() must be true");
assert.ok(instance.isLibusbInitalized, "isLibusbInitalized must be true after refresh()");

var devices = instance.getDevices(); 
assert.notEqual(devices, undefined, "getDevices() must not be undefined");
assert.ok((devices.length > 0), "getDevices() must be larger than 0 (assume that at least one host controller is available)");

for (var i = 0; i < devices.length; i++) {
	var device = devices[i];
	var deviceDesc = undefined;
	var deviceConfigDesc = undefined;
	assert.ok((device.busNumber > 0), "busNumber must be larger than 0");
	assert.ok((device.deviceAddress > 0), "deviceAddress must be larger than 0");
	var id = device.busNumber + ":" + device.deviceAddress;
	assert.ok(((deviceDesc = device.getDeviceDescriptor()) != undefined), "getDeviceDescriptor() must return an object");
	assert.ok(((deviceConfigDesc = device.getConfigDescriptor()) != undefined), "getConfigDescriptor() must return an object");

	var arr = instance.find_by_vid_and_pid(deviceDesc.idVendor, deviceDesc.idProduct);
	assert.ok((arr != undefined), "usb.find_by_vid_and_pid() must return array");
	assert.ok((arr.length > 0), "usb.find_by_vid_and_pid() must return array with length > 0");
	var found = false;
	for (var j = 0; j < arr.length; j++) {
		if ((arr[j].deviceAddress == device.deviceAddress) && (arr[j].busNumber == device.busNumber)) {
			found = true;
			break;
		}
	}
	
	assert.ok(found, "could not find USB interface with find_by_vid_and_pid with equal busNumber and deviceAddress");

//	assert.equal(device.close(), true, "close() must be true because device is opened by prior 
}
assert.ok(instance.close());

console.log("Tests were successful :-)");

{'fraction_non_alphanumeric': 0.14236271342870327, 'fraction_numerical': 0.0053068758652515, 'mean_word_length': 5.924920127795527, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '477583', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1274, 'n_words': 388}