Hello,
I have to test the server which should return the string but then in uppercase. So far I have this : https://github.com/RoelofWobben/Network-simulator/blob/master/src/NetworkSimulator-Tests/KANetworkTest.class.st#L79 but I fail to see how I can test that the package sending back is a uppercase string. Regards, Roelof |
Administrator
|
On Mon, Apr 27, 2020 at 1:56 AM Roelof Wobben via Pharo-users <[hidden email]> wrote: Hello, I think you need to rephrase this question. Either the String class hierarchy has a method named something like #isUppercase or Character does. If only Character has it, you would need to iterate over the received string testing each individual character. Or is your question more about getting the response back to the sending node?
|
Op 27-4-2020 om 18:28 schreef Richard
Sargent:
yep, I want to test if the response back to the sending node is the same string as the sending node is but then all uppercased. Roelof |
Administrator
|
In reply to this post by Richard Sargent
On Mon, Apr 27, 2020 at 9:30 AM Roelof Wobben <[hidden email]> wrote:
Assuming you have the code written that sends a request packet to a server, then makes the server process it and send a response packet back to the original node, the following pseudo-code should show you one way. | requestPacket responsePacket | requestPacket := ... ... send the request and get a response back ... responsePacket := self sendingNode nextReceivedPacket. self assert: responsePacket payload isUppercase description: 'Response should have been uppercase'. self assert: (requestPacket payload equals:
responsePacket payload ignoreCase: true) description: 'Response is not the same string'. Those methods probably exist in Pharo, or something very similar. e.g. it might be #equalsIgnoreCase:.
|
Op 27-4-2020 om 19:16 schreef Richard
Sargent:
oke, I think I can move forward. I have some ideas how to make this work but have to try some things. Thanks Roelof |
Op 27-4-2020 om 19:50 schreef Roelof Wobben via Pharo-users:
This seems to be working testKaNetWorkServer | srcNode destNode link packet link2 packet2 recievedPackage | srcNode := KANetworkNode withAddress: #src. destNode := KANetworkServer withAddress: #dest. link := (KANetworkLink from: srcNode to: destNode) attach; yourself. link2 := (KANetworkLink from: destNode to: srcNode) attach; yourself. packet := KANetworkPacket from: #src to: #dest payload: 'test'. srcNode send: packet via: link. destNode consume: packet. packet2 := link2 packetsToTransmit first. srcNode receive: packet2 from: destNode. recievedPackage := srcNode arrivedPackets first. self assert: recievedPackage payload equals: 'TEST' I hope it is a good one. |
In reply to this post by Pharo Smalltalk Users mailing list
You wrote "I want to test if the response back to the sending node is
the same string as the sending node is but then all uppercased." What is wrong with received = sent asUppercase ? If for some reason you don't like that, then received class = sent class and: [ received size = sent size and: [ received with: sent allSatisfy: [:r :s | r = s asUppercase]]] might do the job, but for two things. (1) SequenceableCollection>> with: another allSatisfy: testBlock "Extension of Collection>>allSatisfy: to test whether corresponding elements of two sequences already known to be the same length all satisfy the given test." self with: another do: [:x :y | (testBlock value: x value: y) ifFalse: [^false]]. ^true is not in Pharo 7. (2) Case conversion in Unicode is *not* a code-point by code-point mapping; it can change the length of a string. received = sent asUppercase is not just the simplest way, it's the safest. On Tue, 28 Apr 2020 at 05:04, Roelof Wobben via Pharo-users <[hidden email]> wrote: > > Op 27-4-2020 om 18:28 schreef Richard Sargent: > > On Mon, Apr 27, 2020 at 1:56 AM Roelof Wobben via Pharo-users <[hidden email]> wrote: >> >> Hello, >> >> I have to test the server which should return the string but then in >> uppercase. >> >> So far I have this : >> https://github.com/RoelofWobben/Network-simulator/blob/master/src/NetworkSimulator-Tests/KANetworkTest.class.st#L79 >> >> but I fail to see how I can test that the package sending back is a >> uppercase string. > > > I think you need to rephrase this question. Either the String class hierarchy has a method named something like #isUppercase or Character does. If only Character has it, you would need to iterate over the received string testing each individual character. > > Or is your question more about getting the response back to the sending node? > > > yep, I want to test if the response back to the sending node is the same string as the sending node is but then all uppercased. > > Roelof > |
Free forum by Nabble | Edit this page |