Postman test never returns "no pass" - postman

I'm trying make a test to my API server and I don't get test result no pass.
My code:
var data = JSON.parse(responseBody);
var days = data["days"];
var total_distance = 0;
days.forEach(function(value,index,array){
total_distance = total_distance + value["distance"];
});
pm.test("Distance data"),function(){
pm.expect(data["total_distance"].to.equal(total_distance));
}
This script never returns no pass. What is my error?

The syntax for your test is incorrect. You have a closing parentheses after pm.test("Distance data" which should actually be the last character on the last line.
Try:
pm.test("Distance data", function () {
pm.expect(data["total_distance"].to.equal(total_distance));
});

Related

Simple Edit check to email out person not working

When someone puts a Y in a cell on a sheet it emails someone.
I am getting it no matter what I enter for the check: Y, F, T, bob - it ALWAYS emails out regardless of the value. It's like the IF is just setting whatever I am asking it to check to the value and doing it. Never seen this in the years of programming..
Can anyone see see something I am missing? I am using an edit trigger
function Checkchange() {
var POs=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(11, 2).getValue();
var rec=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(31, 2).getValue();
var backorder=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(37,5).getValue();
var buyer=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(38,2).getValue();
var QA=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(41,5).getValue();
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(58, 3).setValue(POs)
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(60, 3).setValue(rec)
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(61, 3).setValue(backorder)
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(62, 3).setValue(buyer)
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(63, 3).setValue(QA)
sendEmailsRec();
}
function sendEmailsRec() {
var EMAIL_SENT = 'EMAIL_SENT';
var QAemailAddress = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(60, 1).getValue();
var POs = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(11, 2).getValue();
var message = "Ready for receiving for PO " + POs;
var QAcheckbox = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(31,2).getValue()
var subject = "Ready for receiving for PO" + POs;
var check = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(60, 4).getValue() + QAcheckbox
// if(QAcheckbox ="Y",MailApp.sendEmail(QAemailAddress, subject, message));
if(QAcheckbox ==="hdjkheehehie",
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(60, 3).setValue(EMAIL_SENT)+
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(65, 3).setValue(QAemailAddress + subject + message)+
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(60, 4).setValue(check));
}
Your condition has a wrong logical operator. One = will always return true. Use == or === instead:
if (QAcheckbox == "Y"){
MailApp.sendEmail(QAemailAddress, subject, message));// Always triggers regradless of value
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(63, 3).setValue(EMAIL_SENT));
}
You can read more about operators here.

ML.net prediction are always the same

So I have the following test 2 tests
This test keeps returning the first answer it gives and mimics the way we predict with live data.
if (_bModelPredictor is null)
_bModelPredictor = bModel.MakePredictionFunction<TestClass, Prediction>(mlContext);
if(assumption is null)
assumption = new Prediction();
_bModelPredictor.Predict(new TestClass(myMapper),ref assumption);
DoSomethingWith(assumption );
if the first score is say "XYZ" all following tests are going to give the same answer.
This setup where I test the model with new database data however works:
var result = new Prediction();
var evalution[]= Database.GetTestArray();
var predictor=bModel.MakePredictionFunction<TestClass, Prediction>(mlContext);
for (var i = 0; i < evalution.Length; i++)
{
r++;
//holds the value we think it should have (source database)
var expect = evalution[i].Prediction;
evalution[i].Trend = string.Empty;
//evaluates and puts the trend in "result"
predictor.Predict(new TestClass(evalution[i]),ref result);
score+= result.actual==expect? 1 :-1;
...
}
why is the first one returning a "cashed" answer?

Typescript regex exclude whole string if followed by specific string

I'm been running into weird issues with regex and Typescript in which I'm trying to have my expression replace the value of test minus the first instance if followed by test. In other words, replace the first two lines that have test but for the third line below, replace only the second value of test.
[test]
[test].[db]
[test].[test]
Where it should look like:
[newvalue]
[newvalue].[db]
[test].[newvalue]
I've come up with lots of variations but this is the one that I thought was simple enough to solve it and regex101 can confirm this works:
\[(\w+)\](?!\.\[test\])
But when using Typescript (custom task in VSTS build), it actually replaces the values like this:
[newvalue]
[newvalue].[db]
[newvalue].[test]
Update: It looks like a regex like (test)(?!.test) breaks when changing the use cases removing the square brackets, which makes me think this might be somewhere in the code. Could the problem be with the index that the value is replaced at?
Some of the code in Typescript that is calling this:
var filePattern = tl.getInput("filePattern", true);
var tokenRegex = tl.getInput("tokenRegex", true);
for (var i = 0; i < files.length; i++) {
var file = files[i];
console.info(`Starting regex replacement in [${file}]`);
var contents = fs.readFileSync(file).toString();
var reg = new RegExp(tokenRegex, "g");
// loop through each match
var match: RegExpExecArray;
// keep a separate var for the contents so that the regex index doesn't get messed up
// by replacing items underneath it
var newContents = contents;
while((match = reg.exec(contents)) !== null) {
var vName = match[1];
// find the variable value in the environment
var vValue = tl.getVariable(vName);
if (typeof vValue === 'undefined') {
tl.warning(`Token [${vName}] does not have an environment value`);
} else {
newContents = newContents.replace(match[0], vValue);
console.info(`Replaced token [${vName }]`);
}
}
}
Full code is for the task I'm using this with: https://github.com/colindembovsky/cols-agent-tasks/blob/master/Tasks/ReplaceTokens/replaceTokens.ts
For me this regex is working like you are expecting:
\[(test)\](?!\.\[test\])
with a Typescript code like that
myString.replace(/\[(test)\](?!\.\[test\])/g, "[newvalue]");
Instead, the regex you are using should replace also the [db] part.
I've tried with this code:
class Greeter {
myString1: string;
myString2: string;
myString3: string;
greeting: string;
constructor(str1: string, str2: string, str3: string) {
this.myString1 = str1.replace(/\[(test)\](?!\.\[test\])/g, "[newvalue]");
this.myString2 = str2.replace(/\[(test)\](?!\.\[test\])/g, "[newvalue]");
this.myString3 = str3.replace(/\[(test)\](?!\.\[test\])/g, "[newvalue]");
this.greeting = this.myString1 + "\n" + this.myString2 + "\n" + this.myString3;
}
greet() {
return "Hello, these are your replacements:\n" + this.greeting;
}
}
let greeter = new Greeter("[test]", "[test].[db]", "[test].[test]");
let button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function() {
alert(greeter.greet());
}
document.body.appendChild(button);
Online playground here.

Google Apps Script - find string and return the following characters

The output in the log should be " scripting" because these are the next 10 characters followed by the search criteria "general-purpose". Please visit www.php.net to see what I mean, you will find the search string "general-purpose" on top of www.php.net. I think that I have done some more mistakes in this piece of code, right?
function parse() {
// parse site and store html in response
var response = UrlFetchApp.fetch('www.php.net').getContentText();
// declare search string and new regex object
var str = "/general-purpose/+10-following-charcters";
var regExp = new RegExp("/general-purpose/.{0,10}", "gi");
// find the string "general-purpose" and store the next 10 characters in response
var response = regExp.exec(str[0]);
// expected result in logger output is " scripting"
Logger.log(response);
}
It should be general-purpose(.{0,10}) and not /general-purpose/.{0,10}.
Also regExp.exec(str[0]) should be regExp.exec(str)[1].
This code seems to work fine
var str = UrlFetchApp.fetch('www.php.net').getContentText();
var regExp = new RegExp("general-purpose(.{0,10})", "gi");
var response = regExp.exec(str)[1];
Logger.log(response);

Removing line breaks using Docs GAS

I want to remove all newlines with spaces using google apps script for Docs
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody().editAsText();
body.replaceText("\\t", " "); //works properly for tabs
body.replaceText("\\n", " "); //doesnt work
https://developers.google.com/apps-script/reference/document/body#replacetextsearchpattern-replacement
Any suggestions.?
It seems that the body.replaceText does not allow replacements of what is between paragraphs (the paragraph breaks).
You need to somehow merge all paragraphs into 1 paragraph. You may do it roughly with the following code:
function mergePars() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var pars = body.getParagraphs();
for( var j = 0; j < pars.length; ++j ) {
try {
pars[j].merge();
}
catch (e) {
Logger.log(e); // It will log "Exception: Element must be preceded by an element of the same type."
}
}
}
You may get rid of the try-catch if you get the number of all children in the document (with .getNumChildren()) and then loop through the items checking their DocumentApp.ElementType, and if the previous node was of type DocumentApp.ElementType.PARAGRAPH, apply .merge().