Question: assertion keeps failing have attached my code: method BadNbr ( a: array ) returns ( bn: int ) { if a . Length 2 {
assertion keeps failing have attached my code:
method BadNbra: array returns bn: int
if aLength
return ; No bad neighbors in arrays with fewer than elements
var n : aLength;
Check the wraparound pair last and first elements
if an a
return ; First element is a bad neighbor
Check consecutive pairs in the array
var i :;
while i n
if ai ai
return i ; Found a bad neighbor
i : i ;
return ; No bad neighbors found
method TestBadNbr
Test case : Empty array
var arr : new int;
var res : BadNbrarr;
assert res;
Test case : Array with one element
var arr : new int;
arr :;
var res : BadNbrarr;
assert res;
Test case : Array with two elements where sum is negative
var arr : new int;
arr :;
arr :;
var res : BadNbrarr;
assert res;
Test case : Array with three elements and a bad neighbor pair
var arr : new int;
arr :;
arr :;
arr :;
var res : BadNbrarr;
assert res;
Test case : Array with four elements and a wraparound bad neighbor pair
var arr : new int;
arr :;
arr :;
arr :;
arr :;
var res : BadNbrarr;
assert res;
Additional test case: No bad neighbor
var arr : new int;
arr :;
arr :;
arr :;
var res : BadNbrarr;
assert res; No bad neighbors
Additional test case: Only wraparound is a bad neighbor
var arr : new int;
arr :;
arr :;
arr :;
arr :;
var res : BadNbrarr;
assert res;
rules:
All your solutions should verify, without warning or error, using Dafny version Assessment of the Dafny exercises takes into account efficiency, readability, conciseness and structure. Use the language Dafny as presented in lectures. Do not use language features from the Reference Manual, which includes function method, predicate method, assume or calc
and question:
In the first assignment a neighbour of an element in an array is simply an element next to the element in the array. Every element in an array longer than has in fact two neighbours: a neighbour on the left and another on the right. The first and last elements in an array are special cases that wraparound clockwise: the left neighbour of the first element is the last element in the array, and conversely the right neighbour of the last element is the first element in the array. In this exercise, if a neighbouring pair of element has a negative sum then the right neighbour is said to be bad. For example, the arrays and each has a negativesum pair that wrapsaround, so the neighbour on the right, which is index is the bad neighbour. The array has a negativesum pair at indexes so index is the bad neighbour as it is on the right. The array does not contain a bad neighbour. If there is more than one bad neighbour then the element with the lowest index is the first bad neighbour. The array contains two bad index pairs, namely and so the right neighbours in both, index and index are bad. Index is therefore the first index that is bad. Write a verified method that returns the index of the first bad neighbour of an input array. The signature of the method should be: method BadNbra: array returns bn:int where bn is the index of the first bad neighbour, or if there is no bad neighbour, bn The array may be of any length. Validate that the method works correctly for a series of testcases. You may call your validator anything you like. Submit the file exdfy which should contain method BadNbr and your validator. Notice Dafny method names use camelnotation, but filenames and Dafny predicate names are only lowercase.
please make sure the answer you give me is correct it is not fair I keep using expert solutions which I paid for and you don't give me the right answers
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
