Skip to content

HW_7#8

Open
AnNyiiik wants to merge 7 commits intomainfrom
HW_7
Open

HW_7#8
AnNyiiik wants to merge 7 commits intomainfrom
HW_7

Conversation

@AnNyiiik
Copy link
Owner

@AnNyiiik AnNyiiik commented May 4, 2024

No description provided.


let ``suppliers single thread`` =
seq {
TestCaseData(fun () -> (+) (random.Next(10)) <| random.Next(10))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obj()

Comment on lines +34 to +43
|> Seq.map (fun link ->
async {
try
let! content = readPage link
return Some (String.concat " " [link; content.Length.ToString()])
with
| :? WebException -> return None
} |> Async.StartAsTask)
|> Task.WhenAll
|> Async.AwaitTask

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|> Seq.map (fun link ->
async {
try
let! content = readPage link
return Some (String.concat " " [link; content.Length.ToString()])
with
| :? WebException -> return None
} |> Async.StartAsTask)
|> Task.WhenAll
|> Async.AwaitTask
|> Seq.map (fun link ->
async {
try
let! content = readPage link
return Some (String.concat " " [link; content.Length.ToString()])
with
| :? WebException -> return None
})
|> Async.Parallel

async {
try
let! content = readPage link
return Some (String.concat " " [link; content.Length.ToString()])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше вернуть кортеж (url, length)

Comment on lines +48 to +57
for content in content do
match content with
| Some string ->
if (counter = 0) then
result <- String.concat "" [result; string]
counter <- 1
else
result <- String.concat "\n" [result; string]
| None -> ()
return Some result

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это все не нужно, лучше просто вернуть результат

Comment on lines +64 to +65
|> Option.get
|> should equal "https://edu.spbu.ru/maps/map.html 107400"
Copy link

@DedSec256 DedSec256 May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|> Option.get
|> should equal "https://edu.spbu.ru/maps/map.html 107400"
|> should equal (Some("https://edu.spbu.ru/maps/map.html", 107400))

Comment on lines +15 to +18
use! response = request.AsyncGetResponse()
use reader = new StreamReader(response.GetResponseStream())
let html = reader.ReadToEnd()
return html

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше переписать на httpClient

with
| :? WebException ->
raise (WebException "Incorrect url")
return None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта строчка недостижима, ведь выше кидается эксепшен


return Some content
with
| :? WebException ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В одном случае вы ловите HttpRequestException, в другом WebException, хотя логика одна. Подозрительно.

match result with
| Some sizes ->
Assert.AreEqual(2, sizes.Length)
Assert.Contains(("https://example.com/page1", Some 14), sizes)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше уж сразу весь список сравнить, чем поэлементно

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants