Display discrepancies between collections - fluent-assertions

When asserting the equality of two string collections using
collectionA.Should().Equal(collectionB) the message is:
"Expected collectionA to be equal to {"a", "b", "c", …5 more…} , but {"a", "b", "c", …13 more…} contains 8 item(s) too many."
Is there a way to display the actual discrepancies between the collections?

Related

I have two lists of strings in kotlin, how to concatenate each element of the first list with elements of the second one respective to the positions?

I have two lists:
val a = listOf("a", "b", "c")
val b = listOf("1", "2", "3")
I want to get a list that looks like this: ["a1", "b2", "c3"].
How to do this in the most efficient way?
The easiest way would look like this:
val c = a.zip(b).map {it.first + it.second }

Lucene: TokenFilter to replace chars and produce new tokens as synonyms

I want to map chars like this:
private static final Map<String, String> MAP = Map.of("CH", "X",
"X", "CH",
"I", "Y",
"Y", "I",
"S", "Z",
"Z", "S",
"F", "PH",
"PH", "F");
So for ex, XANTION is tokenized to CHANTION, PHYTOVEIN is tokenized to FITOVEIN, keeping original tokens.
Those are medicine names, it would generate "synonyms" for those, to use when analyzing search terms.
Could I use any existing token filter?

Pandas: Rename duplicate columns in same dataframe and merge

I have the following;
mylist = ["name", "state", "name", "city"]
newlist = ["name1", "state", "name2", "city"]
I have renamed the duplicates. I would like to merge the name1 and name2 and rename to name
This method works well to do this and is clean:
Renamed DataFrame method accepts the dictionary "key: values" that allow you to map the old value to the new value.
Example.
new_df = "read in data source"
col_map = {"name": "name1",
"state": "state",
"name": "name2",
"city": "city"
}
new_df.rename(columns=col_map)
This method should work perfectly fine. Please respond so that our team here in StackOverflow knows that you care about our feedback and are responsive.

Kotlin how to split a list in to sublists

I would like to split a list into a few sublists, but I have no idea how to do it.
Once of my ideas was splitting the list by index of element. For exmaple "B" index is 0, "S" index 2, so I would like to take a part between index 0 - 1 into the first sublist, then the second sublist should be the part between index 2 - 5.
Example of my list:
val listOfObj = listOf("B", "B" , "S", "B", "B", "X", "S", "B", "B", "P")
Result after splitting:
listOf(listOf("B","B"), listOf("S", "B", "B", "X"), listOf("S", "B", "B", "P") )
How do I achieve such a result?
Here it goes. I wrote it from my phone without checking but the idea is basic.
val result = mutableListOf<List<String>>()
var current = mutableList<String>()
listOfObj.forEach { letter ->
if (letter == "S") {
result.add(current)
current = mutableListOf<String>()
}
current.add(letter)
}
if (current.isNotEmpty()) {
result.add(current)
}
You can even create an extension function for a List<T> that gets a separator element as a parameter and returns a list of lists.

How do I obtain a rolling buffer of the last two items emitted from a reactive stream?

I have a stream that emits numbers x. What I want is dx (difference in x) so I need a rolling buffer which emits x_n and x_(n-1) so I can map to dx = x_n - x_(n-1). In a marble diagram this would look like ...
SOURCE --A------B------C--------D------F--G-----
RESULT ---------AB-----BC-------CD-----DF-FG----
This would be handy for other operations like rolling averages etc.
I have checked the operator docs but can't seem to find anything similar. sample is sort of close but is time dependent. buffer is also close but it strictly queues values with no overlap between the buffers.
I'm using RxJS
RXJS 5
RxJS has the bufferCount operator which works as follows ...
observable = Rx.Observable.from(["A", "B", "C", "D", "E", "F"])
bufferSize = 2
overlap = 1
observable.bufferCount(bufferSize, overlap)
.subscribe(vals => console.log(vals));
// Results in,
//
// ["A", "B"]
// ["B", "C"]
// ...
overlap is actually the sample frequency so for example in the above case if overlap = 2 then we would get the normal buffer behaviour.
RXJS 4
You maybe don't even need a buffer for this, a simple concatMap might work for you (of course I don't know any details of your stream:
observable = Rx.Observable.from(["A", "B", "C", "D", "E", "F"]);
observable
.bufferWithCount(2, 1)
.subscribe(all => {
console.log(all);
});
See live here
Two options that will work regardless of the version:
Better
Pairwise
Rx.Observable.from(["A", "B", "C", "D", "E", "F"])
.pairwise()
.subscribe(all => {
console.log(all);
});
bufferCount (or bufferWithCount)
This does exist in RxJS 4 as well as RxJS 5
version == 5.* .* ===> bufferCount
version >= 4.1.0 ===> bufferCount
version < 4.1.0 ===> bufferWithCount
Rx.Observable.from(["A", "B", "C", "D", "E", "F"])
// Buffers of length 2 and skip 1 item (i.e. overlap)
.bufferCount(2, 1)
// the last buffer will have only the last item so drop it
.filter(x => x.length == 2)
.subscribe(all => {
console.log(all);
});
See both here
observable = Rx.Observable.from(["A", "B", "C", "D", "E", "F"]);
we can do
observable
.scan((x, y) => [_.last(x), y], [])
.filter((x) => x[0] !== undefined)
.subscribe(all => {
console.log(all);
});
or if a hot observable:
observable.
zip(observable.skip(1))
.subscribe(all => {
console.log(all);
});
or if a cold observable:
observable
.publish(source_ => source_.zip(source_.skip(1)))
.subscribe(all => {
console.log(all);
});
or easiest:
observable
.pairwise()
.subscribe(all => {
console.log(all);
});