damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

NostrFilterTests.swift (4876B)


      1 //
      2 //  NostrFilterTests.swift
      3 //  damusTests
      4 //
      5 //  Created by Daniel D’Aquino on 2024-05-10.
      6 //
      7 
      8 import XCTest
      9 @testable import damus
     10 
     11 final class NostrFilterTests: XCTestCase {
     12     func testChunkedWithPubKeys() {
     13         // Given a NostrFilter with a list of pubkeys
     14         let test_pubkey_1 = Pubkey(hex: "760f108754eb415561239d4079e71766d87e23f7e71c8e5b00d759e54dd8d082")!
     15         let test_pubkey_2 = Pubkey(hex: "065eab63e939ea2f2f72f2305886b13e5e301302da67b5fe8a18022b278fe872")!
     16         let test_pubkey_3 = Pubkey(hex: "aa146d7c6618ebe993702a74c561f54fc046c8a16e388b828cb2f631a1ed9602")!
     17         let test_pubkey_4 = Pubkey(hex: "2f7108dcd33fb484be3e09cea24a1e96868fbc0842e691ca19db63781801089e")!
     18         let test_pubkey_5 = Pubkey(hex: "1cc7c458e6b565a856d7c3791f4eb5ca5890b1f2433f452ed7a917f9aa0e5250")!
     19         let test_pubkey_6 = Pubkey(hex: "2ee1f46a847b6613c33fd766db1e64c7f727c63774fa3ee952261d2c03b81cf2")!
     20         let test_pubkey_7 = Pubkey(hex: "214664a7ca3236b9dd5f76550d322f390fd70cc12908a2e3ff2cdf50085d4ef2")!
     21         let test_pubkey_8 = Pubkey(hex: "40255b02f3d8ccd6178d50f5ce1c1ac2867b3d919832176957b021c1816fce2f")!
     22         let pubkeys: [Pubkey] = [test_pubkey_1, test_pubkey_2, test_pubkey_3, test_pubkey_4]
     23         let authors: [Pubkey] = [test_pubkey_5, test_pubkey_6, test_pubkey_7, test_pubkey_8]
     24         let filter = NostrFilter(
     25             pubkeys: pubkeys,
     26             authors: authors
     27         )
     28         
     29         let chunked_pubkeys_filters_size_2 = filter.chunked(on: .pubkeys, into: 2)
     30         XCTAssertEqual(chunked_pubkeys_filters_size_2.count, 2)
     31         XCTAssertEqual(chunked_pubkeys_filters_size_2[0].pubkeys, [test_pubkey_1, test_pubkey_2])
     32         XCTAssertEqual(chunked_pubkeys_filters_size_2[1].pubkeys, [test_pubkey_3, test_pubkey_4])
     33         XCTAssertEqual(chunked_pubkeys_filters_size_2[0].authors, authors)
     34         XCTAssertEqual(chunked_pubkeys_filters_size_2[1].authors, authors)
     35         
     36         let chunked_pubkeys_filters_size_3 = filter.chunked(on: .pubkeys, into: 3)
     37         XCTAssertEqual(chunked_pubkeys_filters_size_3.count, 2)
     38         XCTAssertEqual(chunked_pubkeys_filters_size_3[0].pubkeys, [test_pubkey_1, test_pubkey_2, test_pubkey_3])
     39         XCTAssertEqual(chunked_pubkeys_filters_size_3[1].pubkeys, [test_pubkey_4])
     40         XCTAssertEqual(chunked_pubkeys_filters_size_3[0].authors, authors)
     41         XCTAssertEqual(chunked_pubkeys_filters_size_3[1].authors, authors)
     42         
     43         let chunked_pubkeys_filters_size_4 = filter.chunked(on: .pubkeys, into: 4)
     44         XCTAssertEqual(chunked_pubkeys_filters_size_4.count, 1)
     45         XCTAssertEqual(chunked_pubkeys_filters_size_4[0].pubkeys, [test_pubkey_1, test_pubkey_2, test_pubkey_3, test_pubkey_4])
     46         XCTAssertEqual(chunked_pubkeys_filters_size_4[0].authors, authors)
     47         
     48         let chunked_pubkeys_filters_size_5 = filter.chunked(on: .pubkeys, into: 5)
     49         XCTAssertEqual(chunked_pubkeys_filters_size_5.count, 1)
     50         XCTAssertEqual(chunked_pubkeys_filters_size_5[0].pubkeys, [test_pubkey_1, test_pubkey_2, test_pubkey_3, test_pubkey_4])
     51         XCTAssertEqual(chunked_pubkeys_filters_size_5[0].authors, authors)
     52         
     53         let chunked_authors_filters_size_2 = filter.chunked(on: .authors, into: 2)
     54         XCTAssertEqual(chunked_authors_filters_size_2.count, 2)
     55         XCTAssertEqual(chunked_authors_filters_size_2[0].authors, [test_pubkey_5, test_pubkey_6])
     56         XCTAssertEqual(chunked_authors_filters_size_2[1].authors, [test_pubkey_7, test_pubkey_8])
     57         XCTAssertEqual(chunked_authors_filters_size_2[0].pubkeys, pubkeys)
     58         XCTAssertEqual(chunked_authors_filters_size_2[1].pubkeys, pubkeys)
     59 
     60         let chunked_authors_filters_size_3 = filter.chunked(on: .authors, into: 3)
     61         XCTAssertEqual(chunked_authors_filters_size_3.count, 2)
     62         XCTAssertEqual(chunked_authors_filters_size_3[0].authors, [test_pubkey_5, test_pubkey_6, test_pubkey_7])
     63         XCTAssertEqual(chunked_authors_filters_size_3[1].authors, [test_pubkey_8])
     64         XCTAssertEqual(chunked_authors_filters_size_3[0].pubkeys, pubkeys)
     65         XCTAssertEqual(chunked_authors_filters_size_3[1].pubkeys, pubkeys)
     66         
     67         let chunked_authors_filters_size_4 = filter.chunked(on: .authors, into: 4)
     68         XCTAssertEqual(chunked_authors_filters_size_4.count, 1)
     69         XCTAssertEqual(chunked_authors_filters_size_4[0].authors, [test_pubkey_5, test_pubkey_6, test_pubkey_7, test_pubkey_8])
     70         XCTAssertEqual(chunked_authors_filters_size_4[0].pubkeys, pubkeys)
     71         
     72         let chunked_authors_filters_size_5 = filter.chunked(on: .authors, into: 5)
     73         XCTAssertEqual(chunked_authors_filters_size_5.count, 1)
     74         XCTAssertEqual(chunked_authors_filters_size_5[0].authors, [test_pubkey_5, test_pubkey_6, test_pubkey_7, test_pubkey_8])
     75         XCTAssertEqual(chunked_authors_filters_size_5[0].pubkeys, pubkeys)
     76     }
     77 }