This question already has answers here:
Can't use method "contains" in Swift 2
(2 answers)
Closed 6 years ago.
How do I "Call the 'contains()' method on the sequence?"
func deleteSelfieObjectFromList(selfieImgObject: SelfieImage) {
if contains(self.dataArray, selfieImgObject) {
removeObject(&self.dataArray, object: selfieImgObject)
self.collectionView?.reloadData()
}
}
Like this:
let arr = [42]
if arr.contains(42) {
print("found")
}
Related
This question already has answers here:
Uncaught SyntaxError: Cannot use import statement outside a module
(2 answers)
Closed 2 years ago.
I'm trying to import the PositionalAudioHelper. The code is very basic:
// create the PositionalAudio object (passing in the listener)
import * as THREE from 'three';
var sound = new THREE.PositionalAudio( listener );
var helper = new THREE.PositionalAudioHelper(sound);
sound.add( helper );
The webpack error I get is:
"export 'PositionalAudioHelper' (imported as 'THREE') was not found in 'three'
I installed Three using yarn so it may not install the latest version that includes this commit: https://github.com/mrdoob/three.js/pull/15748
Any ideas on how to do this?
Since PositionalAudioHelper is located on the examples directoy, you have to import it like so:
import { PositionalAudioHelper } from 'three/examples/jsm/helpers/PositionalAudioHelper.js';
three.js R116
This question already has answers here:
Post a json body with swagger
(1 answer)
How to describe this POST JSON request body in OpenAPI (Swagger)?
(3 answers)
Swagger POST with json body
(1 answer)
Closed 5 years ago.
I'm getting the error:
0 $refs cannot match any of the following: "#/definitions",
"#/responses"
When trying to use a definition like this (simplified version):
definitions:
Camera:
type: object
properties:
ip:
description: "device IP address"
type: string
required: [ip]
paths:
/cameras:
put:
parameters:
-
$ref: "#/definitions/Camera"
This question already has answers here:
chai test array equality doesn't work as expected
(7 answers)
Closed 6 years ago.
it('GET /customers/ with wrong id', (done) => {
request
.get(`/customers/${wrongId}`)
.end((err, res) => {
expect(res.body).to.equals({});
expect(res).to.have.status(404);
done();
});
});
1) Customers CRUD GET /customers/ with wrong id:
Uncaught AssertionError: expected {} to equal {}
+ expected - actual
You want to use deep if you're trying to compare objects:
expect(res.body).to.deep.equal({});
Or use the eql method:
expect(res.body).to.eql({});
This question already has answers here:
Get a list of function names in a shell script [duplicate]
(4 answers)
Closed 6 years ago.
Lets say I have a script that has a bunch of functions that act like test cases. So for example:
#!/bin/bash
...
function testAssertEqualsWithStrings () {
assertEquals "something" "something"
}
testAssertEqualsWithStrings <--- I dont want to do this
function testAssertEqualsWithIntegers () {
assertEquals 10 10
}
testAssertEqualsWithIntegers <--- I dont want to do this
function testAssertEqualsWithIntegers2 () {
assertEquals 5 $((10 - 5))
}
testAssertEqualsWithIntegers2 <--- I dont want to do this
function testAssertEqualsWithDoubles () {
assertEquals 5.5 5.5
}
testAssertEqualsWithDoubles <--- I dont want to do this
...
Is there a way I can call of these functions in order without having to actually use that explicit function call underneath each test case? The idea is that the user shouldnt have to manage calling the functions. Ideally, the test suite library would do it for them. I just need to know if this is even possible.
Edit: The reason why I dont use just the assert methods is so I can have meaningful output. My current setup allows me to have output such as this:
...
LineNo 14: Passed - testAssertEqualsWithStrings
LineNo 19: Passed - testAssertEqualsWithIntegers
LineNo 24: Passed - testAssertEqualsWithIntegers2
LineNo 29: Passed - testAssertEqualsWithDoubles
LineNo 34: Passed - testAssertEqualsWithDoubles2
...
LineNo 103: testAssertEqualsWithStringsFailure: assertEquals() failed. Expected "something", but got "something else".
LineNo 108: testAssertEqualsWithIntegersFailure: assertEquals() failed. Expected "5", but got "10".
LineNo 115: testAssertEqualsWithArraysFailure: assertEquals() failed. Expected "1,2,3", but got "4,5,6".
LineNo 120: testAssertNotSameWithIntegersFailure: assertNotSame() failed. Expected not "5", but got "5".
LineNo 125: testAssertNotSameWithStringsFailure: assertNotSame() failed. Expected not "same", but got "same".
...
EDIT: Solution that worked for me
function runUnitTests () {
testNames=$(grep "^function" $0 | awk '{print $2}')
testNamesArray=($testNames)
beginUnitTests #prints some pretty output
for testCase in "${testNamesArray[#]}"
do
:
eval $testCase
done
endUnitTests #prints some more pretty output
}
Then I call runUnitTests at the bottom of my test suite.
If you just want to run these functions without calling them, why declare them as functions in the first place?
You either need them to be functions because you are using them multiple times and need the calls to be different each time, in which case I don't see an issue.
Otherwise you just want to run each function once without calling them, which is just running the command. Remove all the function declarations and just call each line.
For this example
#!/bin/bash
...
assertEquals "something" "something" #testAssertEqualsWithStrings
assertEquals 10 10 #testAssertEqualsWithIntegers
assertEquals 5 $((10 - 5)) #testAssertEqualsWithIntegers2
assertEquals 5.5 5.5 #testAssertEqualsWithDoubles
...
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I don't know why whenever I run this code in CMD ,I got this error:
Syntax error, unexpected =>
Here's my code:
hash_brown = (
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
)
puts hash_brown["topping_2"]
first_hash = Hash.new
first_hash["first_name"] = "Jacob"
first_hash["nick_name"] = "Day"
first_hash["last_name"] = "Williams"
puts first_hash["first_hash"]
$end
Please let me know what is wrong with it cause I have checked it thousands of times & didn't found anything!
You should use curly braces ({}) to define Hash objects:
hash_brown = {
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
}